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 09CA0EE57D7 for ; Wed, 11 Sep 2024 21:08:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E7E86B007B; Wed, 11 Sep 2024 17:08:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 770416B0082; Wed, 11 Sep 2024 17:08:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E99D6B0083; Wed, 11 Sep 2024 17:08:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3DD2F6B007B for ; Wed, 11 Sep 2024 17:08:33 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BF176140356 for ; Wed, 11 Sep 2024 21:08:32 +0000 (UTC) X-FDA: 82553696064.17.8211247 Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) by imf04.hostedemail.com (Postfix) with ESMTP id A759E4000E for ; Wed, 11 Sep 2024 21:08:30 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=Q+WzCIfy; spf=pass (imf04.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.44 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726088806; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=S1q9C8g+7qPjQQ1WU75uSsRI/cAkAobRA9aew6drCVM=; b=CV4TL47FYZ1OXeuf0hXTSrvxwE98z+OQfyCvFB6o/0HfR7HzaQgMOZjVNoDYXMwc1dzvTn dA9rgn9mtNYpKuL42dM3VtImw/agKuSeN762AeprGGeuo81mGahRjRptpcGO2Cc++yzXHh ULSB0WTJh9utyge6UrJsrXiPW/U5vr0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726088806; a=rsa-sha256; cv=none; b=Ga6/8nGv1AwcYpYv/tGV3v0DOSKTf14k2dNhRG1RiNKRYQCl/pDk8V0pK26+i+EqGSVlyH n8s6CztAdYrRDv8Snsx2xp4ROhicUDPao+DDEzWcP0u/kAAwKfPykZQdsGudK4FxMYRw0q //5ncguTfjTXZQHTbsp1f7clE4BR7ag= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=Q+WzCIfy; spf=pass (imf04.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.44 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-6c51d1df755so1599066d6.1 for ; Wed, 11 Sep 2024 14:08:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1726088909; x=1726693709; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=S1q9C8g+7qPjQQ1WU75uSsRI/cAkAobRA9aew6drCVM=; b=Q+WzCIfyWFwb4qSKGhWYY+QId2YVcanhEiJDDZuznliiCml/OyUaebaq4zUn3EfI2l +XHPulweW7Bv8WZS+CNbbcs3g1f9Xd650us0E00rRnk/cePcPj26dNW+NsrpEwWqhnWf +ONa+KYWCJHeeAMrujM4tftMhqrZlr15rkdGU+kOmfiUriDpX2ynIFHcmZQrGnZ2k24n 22Vh2bftIi2lThb87X22zzHPJorjZGPxRh2R40J9zzSHleRgNpE9+30RcWMGeo75A2Wc i8GQxjhb2he4Wq4XRxvVBATFdTlT40HWmcAd/ayLkKeJCxEJOomUogIDk4qqFY7gaxaC nINA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726088909; x=1726693709; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=S1q9C8g+7qPjQQ1WU75uSsRI/cAkAobRA9aew6drCVM=; b=f9vp2ZnN6QvZNn/8jw54KfIfuQ0wHgEoR16j/dkSPQfPNUYy/WZAbqX4uZV6hN9lfS lDGRY+NKd6PzFn1szMPdcvRTK8cFT3W2IHnNI65JBeKIeXOBLn9XGtB3IFf35XfYP/A0 x6wj0u6nm+DbBjqpqXR2Exlcuha8oCYPfJ7a25rFx6ESkW/YCl1QTWA8unTzO8T4tBRC 7RC/ibb8S1eGqAO22aZ12BF4bTH/nsJHiL6JwflWOJ9+hAbgiiWR4o68FpuxeZwwBjOd AsF4wyQg9oxgc+dglkPol/8enqpDsAkacggD4WxNHgT3K3goXexW+/fOcNeZmScJi57I y8ZA== X-Forwarded-Encrypted: i=1; AJvYcCX8nKGkJlp3NEGbBa7C/fdD/qqUsaKaPv+WeFE93qywbFEyinuUZfGDPYIUqewu0xhb28ku0OCWYw==@kvack.org X-Gm-Message-State: AOJu0YwsLZGvLNWeG/pPls+11dy7HsZjFuz+QWZKppj4jv2zWD/62yyU riVvy35Z0iDnx5iIreV9UgxQjSpxP+AatQvT+gJWO4Yl8CuKDAjlpDiwShrabLc= X-Google-Smtp-Source: AGHT+IFm928y7rO/WdV4f77rZlTCrW5iXX2snnA//hZsOeffSuUjI+t6T/ZJjtq7H1MGKY7sJbbXHA== X-Received: by 2002:a05:6214:320f:b0:6bf:7bcd:78e3 with SMTP id 6a1803df08f44-6c573530335mr11513076d6.29.1726088909368; Wed, 11 Sep 2024 14:08:29 -0700 (PDT) Received: from localhost ([2603:7000:c01:2716:da5e:d3ff:fee7:26e7]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6c53432954fsm45931186d6.25.2024.09.11.14.08.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 14:08:28 -0700 (PDT) Date: Wed, 11 Sep 2024 17:08:24 -0400 From: Johannes Weiner To: Shakeel Butt Cc: Andrew Morton , Matthew Wilcox , Omar Sandoval , Chris Mason , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Meta kernel team , linux-fsdevel@vger.kernel.org Subject: Re: [PATCH 1/2] mm: optimize truncation of shadow entries Message-ID: <20240911210824.GA117602@cmpxchg.org> References: <20240911173801.4025422-1-shakeel.butt@linux.dev> <20240911173801.4025422-2-shakeel.butt@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240911173801.4025422-2-shakeel.butt@linux.dev> X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: A759E4000E X-Stat-Signature: ho3fgxpxzhgzxkq3inrt7z9rdepu7fki X-HE-Tag: 1726088910-831251 X-HE-Meta: U2FsdGVkX195doYr7jKYPAQVNto5S+A8VFOYPEByIvZ7r1KSR25hPyEiYgNLeLtPDgtgIWebjhB6dxmzNPhY4BGkHMdJQ659XKnWxT3GkNPIRtHclzn8smjl8WMBjENyZpkgxRWoL9enhuwX/8bksn+6I35c8ZjffDD6KubB0fIbx+NFh89xsplW4dv9Qkqi8jqJCckp8L+hjfpbKzDY553CkqZwmzJX9agQRQ2G2QAcKO5iaZ8OGe2OWAHnq/jscbvm1H0Xe704IOWBXCp4gEu2esG3m7Z9LMevmq24eHlP8M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XS3yUwWsbTxgH6ohe2TfQf/+KhU4k7iWWPEknnZKOXE/pK6gT1hSNN1IFhptMDCbzMVJlOHd 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: On Wed, Sep 11, 2024 at 10:38:00AM -0700, Shakeel Butt wrote: > The kernel truncates the page cache in batches of PAGEVEC_SIZE. For each > batch, it traverses the page cache tree and collects the entries (folio > and shadow entries) in the struct folio_batch. For the shadow entries > present in the folio_batch, it has to traverse the page cache tree for > each individual entry to remove them. This patch optimize this by > removing them in a single tree traversal. > > On large machines in our production which run workloads manipulating > large amount of data, we have observed that a large amount of CPUs are > spent on truncation of very large files (100s of GiBs file sizes). More > specifically most of time was spent on shadow entries cleanup, so > optimizing the shadow entries cleanup, even a little bit, has good > impact. > > To evaluate the changes, we created 200GiB file on a fuse fs and in a > memcg. We created the shadow entries by triggering reclaim through > memory.reclaim in that specific memcg and measure the simple truncation > operation. > > # time truncate -s 0 file > > time (sec) > Without 5.164 +- 0.059 > With-patch 4.21 +- 0.066 (18.47% decrease) > > Signed-off-by: Shakeel Butt Looks good to me. One thing that's a bit subtle is that the tree walk assumes indices[] are ordered, such that indices[0] and indices[nr-1] reliably denote the range of interest. AFAICS that's the case for the current callers but if not that could be a painful bug to hunt down. Assessing lowest and highest index in that first batch iteration seems a bit overkill though. Maybe just a comment stating the requirement? Otherwise, Acked-by: Johannes Weiner