From patchwork Tue Mar 26 06:30:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13603618 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 E7DFBC54E67 for ; Tue, 26 Mar 2024 06:29:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7AEB86B009B; Tue, 26 Mar 2024 02:29:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 75D0C6B009C; Tue, 26 Mar 2024 02:29:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D7916B009D; Tue, 26 Mar 2024 02:29:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4781E6B009B for ; Tue, 26 Mar 2024 02:29:27 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1172D1C081E for ; Tue, 26 Mar 2024 06:29:27 +0000 (UTC) X-FDA: 81938213574.14.17F8BFC Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf12.hostedemail.com (Postfix) with ESMTP id DBB6140010 for ; Tue, 26 Mar 2024 06:29:24 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=p9jMLvOo; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=wcN3jXol; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=p9jMLvOo; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=wcN3jXol; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf12.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711434565; 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=N3hPM+dJZjrUpvPFcXGaUP6KRSTdfQGjfQ6el+a/Oj0=; b=f6fsNVVoMyBmPZ018/e7XdEJtMgpIX6x0hpmvIt+tQXFidrxGqidY2mr7oQcwll+zA3R1O 3Fc2UUNFlkyTVTmI38K/AmUuWY7IOvnpiSp73ISc6M+Q1gD7WG4Q7qOtUCM7BWBdB7zbzu LeTfNVd7MgN+K2tAv9cjGckIWKM90ec= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=p9jMLvOo; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=wcN3jXol; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=p9jMLvOo; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=wcN3jXol; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf12.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711434565; a=rsa-sha256; cv=none; b=053F4ynknHZ/6QTN/VmMR+s65PBfZwYzvhCG4gzDqNEOeZDKpL/gb4HGoUMRmfb2wlHSQj 9e9BiEMGQmYxZF8fXsLLkWzSMMM9fHZhEcEO0Bl1XGi359K4tiRM77heoDLPB4sLgv5l9m DXGeda2plvzReduZdyn/3uoftqqcpD8= Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 7FB4C5D1D0; Tue, 26 Mar 2024 06:29:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1711434563; 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=N3hPM+dJZjrUpvPFcXGaUP6KRSTdfQGjfQ6el+a/Oj0=; b=p9jMLvOo6GG9vIewO6sQfRTZ4Mni1Sdahpm3nMkhEbh16q6iJRNISCm+ZrBTYFRWpY5YcT Lqe8NCKu2D1MHp2522H0z8fCEaKmnc3/42wskN9RWdtmSdi8ocsSRMxp3FSWIIq2rdtKNQ LGG0D7tPy5FcURCuhqUWr2cxLFOah9M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1711434563; 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=N3hPM+dJZjrUpvPFcXGaUP6KRSTdfQGjfQ6el+a/Oj0=; b=wcN3jXol/cm7dMUuI/mYHwOilVrIFUsqPKVsZqU5Il++LJ0ABOWuEOeQWXzgRWynNrtLwp TZDUMr4PFDXkmGBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1711434563; 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=N3hPM+dJZjrUpvPFcXGaUP6KRSTdfQGjfQ6el+a/Oj0=; b=p9jMLvOo6GG9vIewO6sQfRTZ4Mni1Sdahpm3nMkhEbh16q6iJRNISCm+ZrBTYFRWpY5YcT Lqe8NCKu2D1MHp2522H0z8fCEaKmnc3/42wskN9RWdtmSdi8ocsSRMxp3FSWIIq2rdtKNQ LGG0D7tPy5FcURCuhqUWr2cxLFOah9M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1711434563; 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=N3hPM+dJZjrUpvPFcXGaUP6KRSTdfQGjfQ6el+a/Oj0=; b=wcN3jXol/cm7dMUuI/mYHwOilVrIFUsqPKVsZqU5Il++LJ0ABOWuEOeQWXzgRWynNrtLwp TZDUMr4PFDXkmGBw== Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 01EA613215; Tue, 26 Mar 2024 06:29:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id KGdpOUJrAmY2YQAAn2gu4w (envelope-from ); Tue, 26 Mar 2024 06:29:22 +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 , Oscar Salvador Subject: [PATCH v3 3/3] mm,page_owner: Fix accounting of pages when migrating Date: Tue, 26 Mar 2024 07:30:36 +0100 Message-ID: <20240326063036.6242-4-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240326063036.6242-1-osalvador@suse.de> References: <20240326063036.6242-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 7yjr9q5pym4zwfexsrbecc16z1q79mix X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: DBB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PORBjiyZB5sc+/ee4Khuq9x4M9RDXe71qy2Rrec3SzDyaD6MsOBXCb8/iFLC7Zn80/zO+EUyTDcM/ABbFJfFF8sSRy//z4mqLmgSlbYGbNtg30bALnZaFhtnzEy04U1xi0JB9x3Ayf8EhTiJzEIDiLxDQ5pYktEFfM7TTwCo62/fDJ4h8UF4WhQj3fNxE7j4hMTIujCSq X-Bogosity: Ham, tests=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. There is an interest in keeping it that way, as otherwise the output will biased towards migration stacks should those operations occur often, but that is not really helpful. The link from the new page to the old stack is being performed by calling __update_page_owner_handle() in __folio_copy_owner(). The only thing that is left is to link the migrate stack to the old page, so the old page will be subtracted from the migrate stack, avoiding by doing so any possible imbalance. Fixes: 217b2119b9e2 ("mm,page_owner: implement the tracking of the stacks count") Signed-off-by: Oscar Salvador Reviewed-by: Vlastimil Babka --- mm/page_owner.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mm/page_owner.c b/mm/page_owner.c index 5df0d6892bdc..b4476f45b376 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -366,9 +366,12 @@ void __split_page_owner(struct page *page, int old_order, int new_order) void __folio_copy_owner(struct folio *newfolio, struct folio *old) { + int i; struct page_ext *old_ext; struct page_ext *new_ext; struct page_owner *old_page_owner; + struct page_owner *new_page_owner; + depot_stack_handle_t migrate_handle; old_ext = page_ext_get(&old->page); if (unlikely(!old_ext)) @@ -381,6 +384,8 @@ void __folio_copy_owner(struct folio *newfolio, struct folio *old) } old_page_owner = get_page_owner(old_ext); + new_page_owner = get_page_owner(new_ext); + migrate_handle = new_page_owner->handle; __update_page_owner_handle(new_ext, old_page_owner->handle, old_page_owner->order, old_page_owner->gfp_mask, old_page_owner->last_migrate_reason, @@ -395,6 +400,16 @@ void __folio_copy_owner(struct folio *newfolio, struct folio *old) old_page_owner->free_pid, old_page_owner->free_tgid, old_page_owner->free_ts_nsec); + /* + * We linked the original stack to the new folio, we need to do the same + * for the new one and the old folio otherwise there will be an imbalance + * when subtracting those pages from the stack. + */ + for (i = 0; i < (1 << new_page_owner->order); i++) { + old_page_owner->handle = migrate_handle; + old_ext = page_ext_next(old_ext); + old_page_owner = get_page_owner(old_ext); + } page_ext_put(new_ext); page_ext_put(old_ext);