Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp877141pxf; Wed, 7 Apr 2021 13:57:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGgjPzV4SgdO9w12v3gb9gJmJa7EunAzKL7X9CE6XgrtAKKHOdnBq8sgH/QqUi/odTvt7T X-Received: by 2002:a92:7007:: with SMTP id l7mr4055888ilc.187.1617829020610; Wed, 07 Apr 2021 13:57:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617829020; cv=none; d=google.com; s=arc-20160816; b=kKAN68jFzOnrSVZ7N8xrMmVjLGn9ZHC8VNTJ7VSIpGd/4piOlIN0unHjS02xleZW6O vUwJK8xxfA6826Unn7d8k2jLGDjJIW4teKL0sWMyxF4ri/Hch4+/+y7gH+WOma2A6meS IrNdEg3i425XGPHhQyXXcAvFnhk6PAU55MQ/7zjhUHahaOChrBu4I+rclVSRtGe+8HEh N1W+kmAuAQK0//DakqfrAemtjONXgzIlRS+A8igv8J7W3aNw22wFACMvQNvAAuivgrn+ AHHjRTngu6XMf3di0YWkbuLFsHlIYx1Wv9KBnYWM8XE1OpuOPE05Iz1CyhQ9cRYmsVp7 qI5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=emeZin8d7OSM4c2irx153jNNqUKEagmom3wCX8zPwMY=; b=HAhc+itqQMOy7MBPY07HGNPavMUDtyD3MPr1+GJciwBq/XD7rOGP7NSqKgI43J1Xg2 psjqm1HrftLDlYtK9XzjhRYZB3WyrGPZUB1wqfW9olhojVfB7jOcqKwfK8ZyifF3fhKX aFCDFXo9uNPEbCipqT+7Pm1byVduTqDKyLN0sm7ocxva8y3aSb+mI3hzn4RnJAxfM2AL tI/BD4H6vmXZInLGIz6tmdgkyXYnGSGgPibl6w+oOjjwFxRA16FLJyhJ+1AiUzO4K2wN QyTmnzsWS+ICNWEu1F8A1yTd2MgxykYoC2b6FxZSXNgkmxzlE7XOt1/e6Tu3v0a4laGa iZtA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c1si21528132jam.95.2021.04.07.13.56.48; Wed, 07 Apr 2021 13:57:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235288AbhDGMZx (ORCPT + 99 others); Wed, 7 Apr 2021 08:25:53 -0400 Received: from mx2.suse.de ([195.135.220.15]:55706 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234902AbhDGMZw (ORCPT ); Wed, 7 Apr 2021 08:25:52 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id DC5F1B135; Wed, 7 Apr 2021 12:25:41 +0000 (UTC) Subject: Re: [PATCH] mm: page_owner: detect page_owner recursion via task_struct To: Sergei Trofimovich , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira References: <20210401223010.3580480-1-slyfox@gentoo.org> <20210401170519.00824fbdf8ab60b720609422@linux-foundation.org> <20210402125039.671f1f40@sf> From: Vlastimil Babka Message-ID: <876f8349-5b64-6be5-6a97-4cf17d7abfb1@suse.cz> Date: Wed, 7 Apr 2021 14:25:41 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210402125039.671f1f40@sf> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/2/21 1:50 PM, Sergei Trofimovich wrote: > On Thu, 1 Apr 2021 17:05:19 -0700 > Andrew Morton wrote: > >> On Thu, 1 Apr 2021 23:30:10 +0100 Sergei Trofimovich wrote: >> >> > Before the change page_owner recursion was detected via fetching >> > backtrace and inspecting it for current instruction pointer. >> > It has a few problems: >> > - it is slightly slow as it requires extra backtrace and a linear >> > stack scan of the result >> > - it is too late to check if backtrace fetching required memory >> > allocation itself (ia64's unwinder requires it). >> > >> > To simplify recursion tracking let's use page_owner recursion depth >> > as a counter in 'struct task_struct'. >> >> Seems like a better approach. >> >> > The change make page_owner=on work on ia64 bu avoiding infinite >> > recursion in: >> > kmalloc() >> > -> __set_page_owner() >> > -> save_stack() >> > -> unwind() [ia64-specific] >> > -> build_script() >> > -> kmalloc() >> > -> __set_page_owner() [we short-circuit here] >> > -> save_stack() >> > -> unwind() [recursion] >> > >> > ... >> > >> > --- a/include/linux/sched.h >> > +++ b/include/linux/sched.h >> > @@ -1371,6 +1371,15 @@ struct task_struct { >> > struct llist_head kretprobe_instances; >> > #endif >> > >> > +#ifdef CONFIG_PAGE_OWNER >> > + /* >> > + * Used by page_owner=on to detect recursion in page tracking. >> > + * Is it fine to have non-atomic ops here if we ever access >> > + * this variable via current->page_owner_depth? >> >> Yes, it is fine. This part of the comment can be removed. > > Cool! Will do. > >> > + */ >> > + unsigned int page_owner_depth; >> > +#endif >> >> Adding to the task_struct has a cost. But I don't expect that >> PAGE_OWNER is commonly used in prodction builds (correct?). > > Yeah, PAGE_OWNER should not be enabled for production kernels. Note that it was converted to use a static key exactly so that it can be always built in production kernels, and simply enabled on boot when needed. Our kernels have it enabled. > Not having extra memory overhead (or layout disruption) is a nice > benefit though. I'll switch to "Unserialized, strictly 'current'" bitfield. > >> > --- a/init/init_task.c >> > +++ b/init/init_task.c >> > @@ -213,6 +213,9 @@ struct task_struct init_task >> > #ifdef CONFIG_SECCOMP >> > .seccomp = { .filter_count = ATOMIC_INIT(0) }, >> > #endif >> > +#ifdef CONFIG_PAGE_OWNER >> > + .page_owner_depth = 0, >> > +#endif >> > }; >> > EXPORT_SYMBOL(init_task); >> >> It will be initialized to zero by the compiler. We can omit this hunk >> entirely. >> >> > --- a/mm/page_owner.c >> > +++ b/mm/page_owner.c >> > @@ -20,6 +20,16 @@ >> > */ >> > #define PAGE_OWNER_STACK_DEPTH (16) >> > >> > +/* >> > + * How many reenters we allow to page_owner. >> > + * >> > + * Sometimes metadata allocation tracking requires more memory to be allocated: >> > + * - when new stack trace is saved to stack depot >> > + * - when backtrace itself is calculated (ia64) >> > + * Instead of falling to infinite recursion give it a chance to recover. >> > + */ >> > +#define PAGE_OWNER_MAX_RECURSION_DEPTH (1) >> >> So this is presently a boolean. Is there any expectation that >> PAGE_OWNER_MAX_RECURSION_DEPTH will ever be greater than 1? If not, we >> could use a single bit in the task_struct. Add it to the >> "Unserialized, strictly 'current'" bitfields. Could make it a 2-bit field if we want >> to permit PAGE_OWNER_MAX_RECURSION_DEPTH=larger. > > Let's settle on depth=1. depth>1 is not trivial for other reasons I don't > completely understand. That's fine, I don't think depth>1 would bring us much benefit anyway. > Follow-up patch incoming. >