From mboxrd@z Thu Jan 1 00:00:00 1970 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 F0926C19F2D for ; Sat, 13 Aug 2022 23:23:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E79386B0073; Sat, 13 Aug 2022 19:23:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E28676B0074; Sat, 13 Aug 2022 19:23:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF1018E0001; Sat, 13 Aug 2022 19:23:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id BCEF66B0073 for ; Sat, 13 Aug 2022 19:23:29 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8B4B140243 for ; Sat, 13 Aug 2022 23:23:29 +0000 (UTC) X-FDA: 79796148138.28.23D531F Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf05.hostedemail.com (Postfix) with ESMTP id 3BFF8100197 for ; Sat, 13 Aug 2022 23:23:28 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1CEC260DC5; Sat, 13 Aug 2022 23:23:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03C87C433D6; Sat, 13 Aug 2022 23:23:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1660433006; bh=ysFtNkgWmL61tA/vu1l6V4vTgJfiMC+3pvDXK+Y2NCo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=faAZbMVOwLQHfw3hBgJv5a3v56W681DVzOI55UQpHQq+Pac+jtYmOphgd2KVIffEQ G9j0bOGPW2JVcN6E0bQBkOUFnVsTsmkvPpRH/V1OPtr+0pWl+h8Hvlpb62Md6mSFHw 1aCs8GRY+7pq7mRyznOvXgRLg67x7O1Z4B+xeLHY= Date: Sat, 13 Aug 2022 16:23:25 -0700 From: Andrew Morton To: cgel.zte@gmail.com Cc: bsingharora@gmail.com, iamjoonsoo.kim@lge.com, mingo@redhat.com, bristot@redhat.com, vschneid@redhat.com, willy@infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Yang Yang , Ran Xiaokai , wangyong Subject: Re: [PATCH 1/2] delayacct: support re-entrance detection of thrashing accounting Message-Id: <20220813162325.57bb5d703d0063d717dc47e9@linux-foundation.org> In-Reply-To: <20220813074108.58196-1-yang.yang29@zte.com.cn> References: <20220813074108.58196-1-yang.yang29@zte.com.cn> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660433008; a=rsa-sha256; cv=none; b=5H4WU016WTlqH2coy/V12wYkx7gRIQ0rrcy0MbxzU6qLvfKvU0AKyR+Rs5SYXR6IFQ2dfS DCf5ThUX6w/GcV/I0FZdutge5Kqlx8CJ85mKy8E34boc/mamd65CKSIfKHuYYvFxYF7hgK njrNwB6EjAGlOs0IhDU7otoLBujY30A= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=faAZbMVO; dmarc=none; spf=pass (imf05.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660433008; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ALwXn/rzguXs/c83HhPYsEjG1fMU8bPFLvG+JPzkRtI=; b=B5+XQxOLUteyKtDBm897STfIGM39I5oKsxSsef5GCMVzKS4/DoL/rfqk47Bc/vLs/vHFi0 ctZu7PEFX5Qh85eSEjIRDwEUYswJ3eeKpB4dt/SIVMiirmOfgNGg3yuu7DEWl7AyGx4vUV l+VUuHJ7RYsQm3ahSZIEHCB5w9Ufmh0= X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 3BFF8100197 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=faAZbMVO; dmarc=none; spf=pass (imf05.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Stat-Signature: g7oyzdxzixwcfxtwyt4ww8maesxwypho X-Rspam-User: X-HE-Tag: 1660433008-880834 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: On Sat, 13 Aug 2022 07:41:09 +0000 cgel.zte@gmail.com wrote: > From: Yang Yang > > Once upon a time, we only support accounting thrashing of page cache. > Then Joonsoo introduced workingset detection for anonymous pages and > we gained the ability to account thrashing of them[1]. > > For page cache thrashing accounting, there is no suitable place to do > it in fs level likes swap_readpage(). So we have to do it in > folio_wait_bit_common(). > > Then for anonymous pages thrashing accounting, we have to do it in > both swap_readpage() and folio_wait_bit_common(). This likes PSI, > so we should let thrashing accounting supports re-entrance detection. > > This patch is to prepare complete thrashing accounting, and is based > on patch "filemap: make the accounting of thrashing more consistent". > > -static inline void delayacct_thrashing_start(void) > +static inline void delayacct_thrashing_start(unsigned long *flags) I don't think that `flags' is a very descriptive name. It might be anything. > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -943,6 +943,10 @@ struct task_struct { > #ifdef CONFIG_CPU_SUP_INTEL > unsigned reported_split_lock:1; > #endif > +#ifdef CONFIG_TASK_DELAY_ACCT > + /* delay due to memory thrashing */ > + unsigned in_thrashing:1; > +#endif OK, saving space in the task_struct is good. > unsigned long atomic_flags; /* Flags requiring atomic access. */ > > diff --git a/kernel/delayacct.c b/kernel/delayacct.c > index 164ed9ef77a3..a5916196022f 100644 > --- a/kernel/delayacct.c > +++ b/kernel/delayacct.c > @@ -214,13 +214,22 @@ void __delayacct_freepages_end(void) > ¤t->delays->freepages_count); > } > > -void __delayacct_thrashing_start(void) > +void __delayacct_thrashing_start(unsigned long *flags) > { > + *flags = current->in_thrashing; > + if (*flags) > + return; Can't we rename `flags' to `in_thrashing' throughout? And may as well give it type `bool'. And convert that bool to/from the bitfield when moving it in and out of the task_struct with *in_thrashing = !!current->in_thrashing; current->in_thrashing = (in_thrashing != 0);