From patchwork Tue Mar 19 18:32:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13597011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D95C4C54E71 for ; Tue, 19 Mar 2024 18:31:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 612886B0092; Tue, 19 Mar 2024 14:31:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5BCDD6B0095; Tue, 19 Mar 2024 14:31:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 437C56B0092; Tue, 19 Mar 2024 14:31:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2DE6D6B008A for ; Tue, 19 Mar 2024 14:31:04 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 01F62A08E2 for ; Tue, 19 Mar 2024 18:31:03 +0000 (UTC) X-FDA: 81914630448.05.745335A Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf03.hostedemail.com (Postfix) with ESMTP id C79A42000A for ; Tue, 19 Mar 2024 18:31:01 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=pfjDOKf1; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=BoyQKkry; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=pfjDOKf1; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=BoyQKkry; spf=pass (imf03.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710873062; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=qBBDN69VSXz+frM1TA/lUSR1pRpjSQYoj51jkyNzGIg=; b=5ceyaqdua0/Ea4ocg3rCr5WBWtmjr5hfnQKptXi5l3uxRv/XcbXbWCyk1cPSZRIL/t/W+E GK74HFJ+yin+/guaXc+L+Zey4i3yHlLGWjrld8NPohaRN8iymVD/L5Lo2lxdccJAc9R4sP h/S9cZ4aMc+pDPQJeVBxPHxU4+p0NqA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710873062; a=rsa-sha256; cv=none; b=WbtRS/QDLcAJuJPvHmBmQBK5cQnP7GGi9dX8P49heBfpxMU6R593f6DDLQf3BrlCKFZohQ HKSsEYmrElt+WdS+xQxVRO7gx1NDOJmDK2pL8Cff2T8fJqiRzHnT8hHt1owahcOCT4gIWZ eoMbyQYGRJxK2gP6utMBM3NDOhoPMEg= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=pfjDOKf1; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=BoyQKkry; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=pfjDOKf1; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=BoyQKkry; spf=pass (imf03.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 45A201F796; Tue, 19 Mar 2024 18:31:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1710873060; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qBBDN69VSXz+frM1TA/lUSR1pRpjSQYoj51jkyNzGIg=; b=pfjDOKf1uxzUNJ613z2gjhyKrzyrDuE8LKyTAT5UQm6rAtbuXqpqdP8UBZJz6l1MH5xLTy smF3WyK1+vBwfEdlPS6dnAELJcWwm1rgYNOA4mM8HwzcOocBjHNKE06257PIzdqNEpzNqF LRSAAF5lzHrFo/Hxb6eW4NNICqTXaJU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1710873060; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qBBDN69VSXz+frM1TA/lUSR1pRpjSQYoj51jkyNzGIg=; b=BoyQKkryctPqM+pUgEPoLlD4178P6d2phPz0yy86fhQEV6syMeGv4jT7b9hWlsYTd8Nmyf SCesS3h7e8TtulCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1710873060; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qBBDN69VSXz+frM1TA/lUSR1pRpjSQYoj51jkyNzGIg=; b=pfjDOKf1uxzUNJ613z2gjhyKrzyrDuE8LKyTAT5UQm6rAtbuXqpqdP8UBZJz6l1MH5xLTy smF3WyK1+vBwfEdlPS6dnAELJcWwm1rgYNOA4mM8HwzcOocBjHNKE06257PIzdqNEpzNqF LRSAAF5lzHrFo/Hxb6eW4NNICqTXaJU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1710873060; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qBBDN69VSXz+frM1TA/lUSR1pRpjSQYoj51jkyNzGIg=; b=BoyQKkryctPqM+pUgEPoLlD4178P6d2phPz0yy86fhQEV6syMeGv4jT7b9hWlsYTd8Nmyf SCesS3h7e8TtulCA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id A91941376B; Tue, 19 Mar 2024 18:30:59 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id wBWfJuPZ+WUcTwAAD6G6ig (envelope-from ); Tue, 19 Mar 2024 18:30:59 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Marco Elver , Andrey Konovalov , Alexander Potapenko , Tetsuo Handa , Oscar Salvador Subject: [PATCH v2 2/2] mm,page_owner: Fix accounting of pages when migrating Date: Tue, 19 Mar 2024 19:32:12 +0100 Message-ID: <20240319183212.17156-3-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240319183212.17156-1-osalvador@suse.de> References: <20240319183212.17156-1-osalvador@suse.de> MIME-Version: 1.0 X-Spamd-Bar: +++ X-Rspamd-Queue-Id: C79A42000A X-Rspam-User: X-Stat-Signature: wyajthypp9zywxawfd9hgo4n8p4kfcgy X-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=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Upon migration, new allocated pages are being given the handle of the old pages. This is problematic because it means that for the stack which allocated the old page, we will be substracting the old page + the new one when that page is freed, creating an accounting imbalance. Fix this by adding a new migrate_handle in the page_owner struct, and record the handle that allocated the new page in __folio_copy_owner(). Upon freeing, we check whether we have a migrate_handle, and if we do, we use migrate_handle for dec_stack_record_count(), which will subtract those pages from its right handle. Fixes: 217b2119b9e2 ("mm,page_owner: implement the tracking of the stacks count") Signed-off-by: Oscar Salvador --- mm/page_owner.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mm/page_owner.c b/mm/page_owner.c index 2613805cb665..1a7d0d1dc640 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -27,6 +27,7 @@ struct page_owner { gfp_t gfp_mask; depot_stack_handle_t handle; depot_stack_handle_t free_handle; + depot_stack_handle_t migrate_handle; u64 ts_nsec; u64 free_ts_nsec; char comm[TASK_COMM_LEN]; @@ -240,7 +241,15 @@ void __reset_page_owner(struct page *page, unsigned short order) return; page_owner = get_page_owner(page_ext); - alloc_handle = page_owner->handle; + /* + * If this page was allocated for migration purposes, its handle doesn't + * reference the stack it was allocated from, so make sure to use the + * migrate_handle in order to subtract it from the right stack. + */ + if (!page_owner->migrate_handle) + alloc_handle = page_owner->handle; + else + alloc_handle = page_owner->migrate_handle; handle = save_stack(GFP_NOWAIT | __GFP_NOWARN); for (i = 0; i < (1 << order); i++) { @@ -277,6 +286,7 @@ static inline void __set_page_owner_handle(struct page_ext *page_ext, page_owner->handle = handle; page_owner->order = order; page_owner->gfp_mask = gfp_mask; + page_owner->migrate_handle = 0; page_owner->last_migrate_reason = -1; page_owner->pid = current->pid; page_owner->tgid = current->tgid; @@ -358,6 +368,7 @@ void __folio_copy_owner(struct folio *newfolio, struct folio *old) new_page_owner->gfp_mask = old_page_owner->gfp_mask; new_page_owner->last_migrate_reason = old_page_owner->last_migrate_reason; + new_page_owner->migrate_handle = new_page_owner->handle; new_page_owner->handle = old_page_owner->handle; new_page_owner->pid = old_page_owner->pid; new_page_owner->tgid = old_page_owner->tgid;