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 972FAEE57D7 for ; Wed, 11 Sep 2024 22:20:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 29F246B0085; Wed, 11 Sep 2024 18:20:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 24FCF6B0089; Wed, 11 Sep 2024 18:20:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1177C6B008A; Wed, 11 Sep 2024 18:20:51 -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 E8FEB6B0085 for ; Wed, 11 Sep 2024 18:20:50 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5FC171A1179 for ; Wed, 11 Sep 2024 22:20:50 +0000 (UTC) X-FDA: 82553878260.15.2FF6505 Received: from out-180.mta1.migadu.com (out-180.mta1.migadu.com [95.215.58.180]) by imf25.hostedemail.com (Postfix) with ESMTP id 7F169A000C for ; Wed, 11 Sep 2024 22:20:48 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=pMVATVqj; spf=pass (imf25.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.180 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726093144; 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=+MlZ0mawDlEwUZp7Ryvv2HfbC6bAGFXeox7y/af6rjw=; b=dlaGegHTMSjWbQ8hdAhDivIDU0HN9H201JSLtS6x8akRp2lIF5pdjazezuoVh8JqcfTzCD ZelnDCSXTNM7qpIOMPrI4onHPqT+jWnjBKbBOByWK+8w8ezwq8KAXk72VbZjBQ3FkmsTam N2v9HWItHYWhpvHeVaR5XbOhBRW2lt8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726093144; a=rsa-sha256; cv=none; b=Tu7Yws4i3jfCyR54/puCBx39XhVQk7wvxxBwu5gD8N1iZYSWMdNxXk4ygIgkK9ZH77Tjtf 1uud5pC0/mL/aV1iHby4EwOhyTO23uFNVlprrP7j+FhKUtWz8tvY5fllVKK1hVLjjSSRb4 tVbNskfZ/RLvu3vezzvd8EmEGtE4iA8= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=pMVATVqj; spf=pass (imf25.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.180 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev Date: Wed, 11 Sep 2024 15:20:40 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1726093246; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+MlZ0mawDlEwUZp7Ryvv2HfbC6bAGFXeox7y/af6rjw=; b=pMVATVqjn2sWMKvjniszDv5T2Of5AaOmG2EmPyXwBXqWjBIBYTzaorch1TZ51gv/2oBYMh VdIiOs6cErsW9q1Z0utKsnhO0fR7HrZQo8hl4F+HRA88OxKe22o6LxP6pi5Bn3OPRsRLIa lA5/saYfi/jNkOZZ5liAM1+3bHYLHkU= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Johannes Weiner 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: <3xy45w5enrkvnyvxwufxfgzmpmii6au4o6wbepqkl5qfiygizc@2c4b7jcs676y> References: <20240911173801.4025422-1-shakeel.butt@linux.dev> <20240911173801.4025422-2-shakeel.butt@linux.dev> <20240911210824.GA117602@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240911210824.GA117602@cmpxchg.org> X-Migadu-Flow: FLOW_OUT X-Stat-Signature: tda1iogaurws7fats3poc83et1tkd7st X-Rspamd-Queue-Id: 7F169A000C X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1726093248-537537 X-HE-Meta: U2FsdGVkX193GTkHPYGpSSSKzhuzmXFu4UU7VjTpmq2+TJkMEN96jreeWOKtHXEhDfVZ08dQnuVvXXPawVsF9Q5/ylKkrzn4Sa9CjytHTzrH0lQg1EWTnlfDuQ+RX2ZI6H58pgc5FYbbfUKdmS2m5bQlMK7+W1wtDr5cGzpVUSGTdkDdY1m/AlsowNpkCMcQ4pn5nps93NduuCKkc4VJIEqaokDmMPJ2L6Wk0LoP1TU4rr50kzX2i9HeiraE8nczsfnRHjF4k9JeHOJyNTTz5HnqAX8sPcFFY/rKg+YqGkHztzhJrrUkYHuYI4Dauq1k2zqcuG/Oqex8tRnTcY8/KkOG/n4eXNGt1vkSCghqeV+YNOa/lDynJVZ7PsWuuD7JvKY0hYudpPWCBDd8AoFwONVKkoXczzER6DV1JRGdrzBweeHa6Fv9n3NfZSs10Ckay1O1PuoUtppclCJ2tfHqRCgpGLdVX8rYxiEotWBng0HAalIciAoFXG2O/Y4wZw9ek2MnTLQRM5tEdkC11Zi9zeNfP1JsCXbu78aF8jb5PxJKPcrDUBCRzTpSpY86GvpaZTTmr5rJeWku2t2dkEYcKLHM9fphaOq/fWi27xXb5fc16sQt0rTGd4WaxR2f5C54Eqi12N5oN0bq39ndx673pj7idKfsp8RA/CcYtfWdTFhk6JMVkftrm4NkAKkzPDQfrgyUOibYk9VGdOja+9SadfYzDlsvXh55b0p7K2/oaxcrHYp9NU/sFUw0qlcBrMK/N1veMMq/injpW+/jQQkwbijX5dqQ9CpqRFCjLzHf3kyvLSPuPPqXY29hwtzZhTjb07dF5HTv/lKcXEEIPTJJ9N4mt0MEkehqOm6dLBTUYFSi/mKaXh5+n7J7QQeHBHTb9ffw78+23MR7F5EQzKTmgic4cpLIK4Pipnsxcw9ZhnS48iwYKA7p35M+/2UqoYHL2N8g59VkzXi9InR2H+3 jw+JO3H3 XuM5APAbiAIqjG5o34YcJ+JleccXXjIfCmkcR3M4eePsMhG7Ryukd6wMH/sF6wbztVFcF/3ls6Lvm64K9BkAxVVCu59N7CWCj3al6XsOxnPYHbs0HOV4+0o9RibzNWfBq1PYKhc2yHz9jiMIuChu9rM4Sgu9UlfBERfVisWpRZsi9S2Kmw4L8+BuYkfHrKB1UbsCL0vrzlndmZ1c= 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 05:08:24PM GMT, Johannes Weiner wrote: > 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. The current callers use find_get_entries() and find_lock_entries() to fill up the indices array which provides this guarantee. > > Assessing lowest and highest index in that first batch iteration seems > a bit overkill though. Maybe just a comment stating the requirement? I will add a comment in v2. > > Otherwise, > > Acked-by: Johannes Weiner Thanks for the review.