Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp362826rdd; Tue, 9 Jan 2024 06:36:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHyhZAuKgBRnH+d191jhOrlPdH8YTi6YA9wJKAEFv2deJnmUWAOQ/27c7RLtomq+5Xg6Z4i X-Received: by 2002:a05:6358:5928:b0:175:9b4d:5d78 with SMTP id g40-20020a056358592800b001759b4d5d78mr1860876rwf.18.1704810965875; Tue, 09 Jan 2024 06:36:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704810965; cv=none; d=google.com; s=arc-20160816; b=FoeZ1wC0FFRWJR96OzWGJxCRIySxU6YGIFO0LdqNnSZBOYuGLXovj5TSTHjGyA0zAl hsC1cBQK3qclDdXswsaoFigvwF1VrzbGwS7lmv6CpwaNoFMGZEaH4QtCd3jZGchZq4F1 wyo9/rfAUt5adkhVYrk9AxWKWUlbU0KxWQyWrnDMDdrfwtR1tLr00KyyYGy4BMn9UqXJ VnKadRqHYeDIuE5FU8Cqk1aXgnMdEFmO5Stjm3rNgvdMtNnR1EOwNc5UFDxGZ+vAZOPP qw3/cuQk2pndEazem+yW+3SKBCPGH5BcI9KMTUn05AcGIfnCkESwxA9+MCPN78ZLU1nF 3dxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=cca0/i33EOqMAkZgYIeSRXbVYWRM3R2G+zhbkmE3gJs=; fh=C1THyYX8mZv7/wM+MHV1ZUcnQSQiZbUrxk0HRhdecS4=; b=lAh7Mdqo6T8QfNXceyDD35EMehCYjv+sZdRDJ/laiGwtNAfppBHAyijevNbDfjvCJK s/4lLaVIUntqtpf281XLQO4OcA59LlyvTioRDnX/9co9M50m/Wg4+5ATIELePgkV0THl BjOq5/XbfB/+ywOYd0ge749jP6cGkFQq9VScHVqGC5jiM8jcTlPq80D5KVYU3mP95oNG +2ggxcyMUAel5eNvZAga8JzzUKS+Sr7DGpIBA9UOxgOVoy92kh+/KRBOy/GVXuQXQkhb a7A+28OTHVM/5oAoUgdQB1j7tbwB7zZvzltlQbS8HptAcbJHEhcM/QunSyDb6NUxjthc De1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=ToQx4GGb; spf=pass (google.com: domain of linux-kernel+bounces-20994-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20994-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id z1-20020a636501000000b005cdfaea88adsi1472823pgb.774.2024.01.09.06.36.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 06:36:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-20994-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=ToQx4GGb; spf=pass (google.com: domain of linux-kernel+bounces-20994-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20994-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B1586283607 for ; Tue, 9 Jan 2024 14:35:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 93F9C3A8EF; Tue, 9 Jan 2024 14:34:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ToQx4GGb" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F62E3A1BA; Tue, 9 Jan 2024 14:34:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=cca0/i33EOqMAkZgYIeSRXbVYWRM3R2G+zhbkmE3gJs=; b=ToQx4GGbYUyKYdHFRtG64tsI0E 6B1SLA7rgJoaFg6yV275YZFQodqDN4YazJdaRo6sLRwxzDy+THnFq1skLIjawWPpwu0hrC80kO/GT PWfsA1BBnWCOtaLvsiwJiOSxT6322c9oa9kxga1dOg6iPY9KxKXcoXNvM2rx3qltZuujcRUBee3cm WN8eN2/Em1DgWFgGc+JBEFB67pyM4zUNj/i1Pj2pFnRJ4zYGv1dANBmydKmytpTwYqbHxzOcbEBPt sXFER4VtTGWV3dXlqTRq8me73WxnozzI9kQzq82DU8D7t8UOsME8o4brJ1Sh/kqO9Thtxi132IRaS Rmjiyl6g==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1rNDB1-009xrU-0M; Tue, 09 Jan 2024 14:33:59 +0000 From: "Matthew Wilcox (Oracle)" To: Jonathan Corbet Cc: "Matthew Wilcox (Oracle)" , linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/8] buffer: Add kernel-doc for try_to_free_buffers() Date: Tue, 9 Jan 2024 14:33:52 +0000 Message-Id: <20240109143357.2375046-4-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20240109143357.2375046-1-willy@infradead.org> References: <20240109143357.2375046-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The documentation for this function has become separated from it over time; move it to the right place and turn it into kernel-doc. Mild editing of the content to make it more about what the function does, and less about how it does it. Signed-off-by: Matthew Wilcox (Oracle) --- fs/buffer.c | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 071f01b28c90..25861241657f 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2864,26 +2864,6 @@ int sync_dirty_buffer(struct buffer_head *bh) } EXPORT_SYMBOL(sync_dirty_buffer); -/* - * try_to_free_buffers() checks if all the buffers on this particular folio - * are unused, and releases them if so. - * - * Exclusion against try_to_free_buffers may be obtained by either - * locking the folio or by holding its mapping's i_private_lock. - * - * If the folio is dirty but all the buffers are clean then we need to - * be sure to mark the folio clean as well. This is because the folio - * may be against a block device, and a later reattachment of buffers - * to a dirty folio will set *all* buffers dirty. Which would corrupt - * filesystem data on the same device. - * - * The same applies to regular filesystem folios: if all the buffers are - * clean then we set the folio clean and proceed. To do that, we require - * total exclusion from block_dirty_folio(). That is obtained with - * i_private_lock. - * - * try_to_free_buffers() is non-blocking. - */ static inline int buffer_busy(struct buffer_head *bh) { return atomic_read(&bh->b_count) | @@ -2917,6 +2897,30 @@ drop_buffers(struct folio *folio, struct buffer_head **buffers_to_free) return false; } +/** + * try_to_free_buffers: Release buffers attached to this folio. + * @folio: The folio. + * + * If any buffers are in use (dirty, under writeback, elevated refcount), + * no buffers will be freed. + * + * If the folio is dirty but all the buffers are clean then we need to + * be sure to mark the folio clean as well. This is because the folio + * may be against a block device, and a later reattachment of buffers + * to a dirty folio will set *all* buffers dirty. Which would corrupt + * filesystem data on the same device. + * + * The same applies to regular filesystem folios: if all the buffers are + * clean then we set the folio clean and proceed. To do that, we require + * total exclusion from block_dirty_folio(). That is obtained with + * i_private_lock. + * + * Exclusion against try_to_free_buffers may be obtained by either + * locking the folio or by holding its mapping's i_private_lock. + * + * Context: Process context. @folio must be locked. Will not sleep. + * Return: true if all buffers attached to this folio were freed. + */ bool try_to_free_buffers(struct folio *folio) { struct address_space * const mapping = folio->mapping; -- 2.43.0