From patchwork Thu Feb 8 23:45:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13550766 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 EE3B9C4828F for ; Thu, 8 Feb 2024 23:45:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5EC606B0081; Thu, 8 Feb 2024 18:45:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 59C8E6B0082; Thu, 8 Feb 2024 18:45:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A2606B0083; Thu, 8 Feb 2024 18:45:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 226BA6B0081 for ; Thu, 8 Feb 2024 18:45:18 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id EED2540F53 for ; Thu, 8 Feb 2024 23:45:17 +0000 (UTC) X-FDA: 81770270274.29.3931B77 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf01.hostedemail.com (Postfix) with ESMTP id ABC2E40011 for ; Thu, 8 Feb 2024 23:45:15 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ZwBUTcSH; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=P94itunw; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ZwBUTcSH; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=P94itunw; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf01.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 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=1707435916; 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=SOtnmJyjTMio6JnPiONHFMtYXU8AmDD2FzaIP6UxlE0=; b=gpvYIXJwFzm3WaBhMZ9qxGm9mEIXmZDKw6oE7wEufJ1fJbMis/dJK2o9/aPZrOVnZGHJnv B3+yzqtCPYVaBLrvD+26jKw7+NOjIek4B55LnvNu4q5glpFfFiOkaWgoxR9QwUDLbW6aCK XYh7RnficxZ2Ocx0GMerOa9RhN6s8AI= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ZwBUTcSH; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=P94itunw; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ZwBUTcSH; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=P94itunw; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf01.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707435916; a=rsa-sha256; cv=none; b=xRVbotqlBpLm+M5cOoz9Tupqbq4Z1cyzkEv93og1t7YbcFL4jt1Hvf44qC9ocr3AKn3M/z 0RBxdFIjF99H9iWbkJ/24KDV+jBCQujVpNNv7Tps6ZjeMaIURQcDsoY7wXGkf46RD0GwoW QSMlFIIAW2svgw3TkTkOt3R8Nzhs68Q= 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-out1.suse.de (Postfix) with ESMTPS id 0223922315; Thu, 8 Feb 2024 23:45:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707435914; 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=SOtnmJyjTMio6JnPiONHFMtYXU8AmDD2FzaIP6UxlE0=; b=ZwBUTcSH+yLhiMahPKyOuS6osd4fSVbDvSv0ya9UGW8LetG88/d1KWoq3atCJvOX06Hwzy xBwNVvWy/AX19x6X2g6vJmpbvfXHPxyd/hbLKimF1aN1lbKPslwvtSlUR1c71B5sF9gdOZ 4zAFuPrZgEa8zf1XjkjfiZ8IofdJMc4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707435914; 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=SOtnmJyjTMio6JnPiONHFMtYXU8AmDD2FzaIP6UxlE0=; b=P94itunwwRNbkd3dZY3MmvmKcwBH9vGwln8BkDZ7EFifY/wZ5ri9E0MFoYpFJKTDwXvZyN KTNeSOR1XY3gdoCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707435914; 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=SOtnmJyjTMio6JnPiONHFMtYXU8AmDD2FzaIP6UxlE0=; b=ZwBUTcSH+yLhiMahPKyOuS6osd4fSVbDvSv0ya9UGW8LetG88/d1KWoq3atCJvOX06Hwzy xBwNVvWy/AX19x6X2g6vJmpbvfXHPxyd/hbLKimF1aN1lbKPslwvtSlUR1c71B5sF9gdOZ 4zAFuPrZgEa8zf1XjkjfiZ8IofdJMc4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707435914; 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=SOtnmJyjTMio6JnPiONHFMtYXU8AmDD2FzaIP6UxlE0=; b=P94itunwwRNbkd3dZY3MmvmKcwBH9vGwln8BkDZ7EFifY/wZ5ri9E0MFoYpFJKTDwXvZyN KTNeSOR1XY3gdoCA== 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 6076D13984; Thu, 8 Feb 2024 23:45:13 +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 ODavFIlnxWWUfAAAD6G6ig (envelope-from ); Thu, 08 Feb 2024 23:45:13 +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 v7 2/4] mm,page_owner: Implement the tracking of the stacks count Date: Fri, 9 Feb 2024 00:45:37 +0100 Message-ID: <20240208234539.19113-3-osalvador@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240208234539.19113-1-osalvador@suse.de> References: <20240208234539.19113-1-osalvador@suse.de> MIME-Version: 1.0 X-Spamd-Bar: + X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: ABC2E40011 X-Stat-Signature: gt83irzx8m5gppfrkaxzqem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SQ1p4in9BWVe4KZXBsXWtnIoCdhOEndcGiIZs//0UlHljnFmf/utZoJzv7afvV7DbsjdFIMzshD7tl17D9coNJ2w55xNQbtxthUFWsICgjorMbtn3NJRH1rKBCIpQQ6eNIrVfmJoaUQHoC9c5MYZr0LQIGG8YhDrRvNd+/brOhx/LPWrF7abiTsflQ+bQRXmn5dMb2ukcu4uLt0y2xuF4lhbN3CBNIP7C+smT08xxugg3rygaw== 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: page_owner needs to increment a stack_record refcount when a new allocation occurs, and decrement it on a free operation. In order to do that, we need to have a way to get a stack_record from a handle. Implement stack_depot_get_stack() which just does that, and make it public so page_owner can use it. Also implement {inc,dec}_stack_record_count() which increments or decrements on respective allocation and free operations, via __reset_page_owner() (free operation) and __set_page_owner() (alloc operation). Signed-off-by: Oscar Salvador --- include/linux/stackdepot.h | 8 ++++++++ lib/stackdepot.c | 8 ++++++++ mm/page_owner.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index d0dcf4aebfb4..ac62de4d4999 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -175,6 +175,14 @@ depot_stack_handle_t stack_depot_save_flags(unsigned long *entries, depot_stack_handle_t stack_depot_save(unsigned long *entries, unsigned int nr_entries, gfp_t gfp_flags); +/** + * stack_depo_get_stack - Get a pointer to a stack struct + * @handle: Stack depot handle + * + * Return: Returns a pointer to a stack struct + */ +struct stack_record *stack_depot_get_stack(depot_stack_handle_t handle); + /** * stack_depot_fetch - Fetch a stack trace from stack depot * diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 16c8a1bf0008..197c355601f9 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -681,6 +681,14 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, } EXPORT_SYMBOL_GPL(stack_depot_save); +struct stack_record *stack_depot_get_stack(depot_stack_handle_t handle) +{ + if (!handle) + return NULL; + + return depot_fetch_stack(handle); +} + unsigned int stack_depot_fetch(depot_stack_handle_t handle, unsigned long **entries) { diff --git a/mm/page_owner.c b/mm/page_owner.c index 5634e5d890f8..0adf41702b9d 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -61,6 +61,22 @@ static __init bool need_page_owner(void) return page_owner_enabled; } +static void inc_stack_record_count(depot_stack_handle_t handle) +{ + struct stack_record *stack = stack_depot_get_stack(handle); + + if (stack) + refcount_inc(&stack->count); +} + +static void dec_stack_record_count(depot_stack_handle_t handle) +{ + struct stack_record *stack = stack_depot_get_stack(handle); + + if (stack) + refcount_dec(&stack->count); +} + static __always_inline depot_stack_handle_t create_dummy_stack(void) { unsigned long entries[4]; @@ -140,6 +156,7 @@ void __reset_page_owner(struct page *page, unsigned short order) int i; struct page_ext *page_ext; depot_stack_handle_t handle; + depot_stack_handle_t alloc_handle; struct page_owner *page_owner; u64 free_ts_nsec = local_clock(); @@ -147,6 +164,9 @@ void __reset_page_owner(struct page *page, unsigned short order) if (unlikely(!page_ext)) return; + page_owner = get_page_owner(page_ext); + alloc_handle = page_owner->handle; + handle = save_stack(GFP_NOWAIT | __GFP_NOWARN); for (i = 0; i < (1 << order); i++) { __clear_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags); @@ -158,6 +178,15 @@ void __reset_page_owner(struct page *page, unsigned short order) page_ext = page_ext_next(page_ext); } page_ext_put(page_ext); + if (alloc_handle != early_handle) + /* + * early_handle is being set as a handle for all those + * early allocated pages. See init_pages_in_zone(). + * Since their refcount is not being incremented because + * the machinery is not ready yet, we cannot decrement + * their refcount either. + */ + dec_stack_record_count(alloc_handle); } static inline void __set_page_owner_handle(struct page_ext *page_ext, @@ -199,6 +228,7 @@ noinline void __set_page_owner(struct page *page, unsigned short order, return; __set_page_owner_handle(page_ext, handle, order, gfp_mask); page_ext_put(page_ext); + inc_stack_record_count(handle); } void __set_page_owner_migrate_reason(struct page *page, int reason)