Received: by 2002:ab2:23c8:0:b0:1f2:fdbc:cb93 with SMTP id a8csp17463lqe; Tue, 26 Mar 2024 18:28:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVhPFGf1eUKWv0lNLN2uvSrFkyWJ/b12HNqRXOpPZ66AMq4ZZ13lFQpUVda8C9FEzq9wpt3TLAwoPVW4S0hWUISiWZNIY7huDXH9Tom2g== X-Google-Smtp-Source: AGHT+IFd7GKtewlAxCd+rLF+hlcFcZdfqHl2RAhCi9ovunbRHuuXIHGVPcH18nSz/lM9vq+0f+KW X-Received: by 2002:a05:6a20:ce4b:b0:1a3:bdd2:a9a0 with SMTP id id11-20020a056a20ce4b00b001a3bdd2a9a0mr4271094pzb.20.1711502918419; Tue, 26 Mar 2024 18:28:38 -0700 (PDT) Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id q20-20020a631f54000000b005e438e99128si10722906pgm.721.2024.03.26.18.28.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 18:28:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-120171-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=ia9kcfKB; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-120171-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120171-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 4BD0BB212BB for ; Wed, 27 Mar 2024 01:26:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D2DA1BF3F; Wed, 27 Mar 2024 01:26:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ia9kcfKB" Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1E563DAC0D for ; Wed, 27 Mar 2024 01:26:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711502774; cv=none; b=J29+O8DXy1QvfAhYdFS0TKjwGfj3dx85r1+RH1DX0acrXr7kXdOkP1v88YESddWgpQvfFYLXVlHgV3fQt9ZcpX7EXnrj9h48/HPnQ0jP/ze6vQligW4aYqUbJzCVUfObnGIgu/hdQqwpK2ouxCH5OSZJjuUJWJ0nQwWzzCbsAaU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711502774; c=relaxed/simple; bh=GqzERt7Hb1xZRdLM5Wl2ICX6XNGzv9UMGiH4kpKGUN0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=PkUizqeSx+7NyOYPWXsq1rnFqOW5allin8u/7W63JNBcXgs9+4zACYoHhwzNhrpMOsdEAUurUCUH/m2QICau9KSI0alDrYQLPx63DzPJuFhiXk44/3c9u9w2e/Wv83tv6g2bDeofL/t/XtRQx7SIqoQe6Ues3mbQUDrYx7nkhnI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ia9kcfKB; arc=none smtp.client-ip=209.85.208.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2d41d1bedc9so115764781fa.3 for ; Tue, 26 Mar 2024 18:26:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711502771; x=1712107571; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=RYZGEUhGrOB0Ufj0v9g5JNZSmjlSrrhBE0eNJdDGR9E=; b=ia9kcfKBZ8l6ONDZLL3qCJ4+aKAu1mOY1DxsoxUt1GIoTjOidaZ9dW7NLaKYL6v5z1 n6BVk1mR2laxDf2HukNLuA/eB+I6W/2dSDPlSegJJ9QC80TAE5lXhvX4rWBJi4Kv+cF2 X4euRrn+m8B1NHUq87sByRCaQPsXtrOsVYiPgDb2CXQhJMdnH6ij7jlvmYxIUWW3V5Bu eJ0g9sFc1NOjln4QbEheVRVmCMEmS9y7vcSmDnuBlc/TXZ4FjzUFhB1suIc++AyHoS85 wBCy82panD5kDrkSZiOJX9Oz4Pu180y0Bt8KVdWCXi2DOqR3P/ah7F5bTVAoZGrGhpXn JPYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711502771; x=1712107571; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RYZGEUhGrOB0Ufj0v9g5JNZSmjlSrrhBE0eNJdDGR9E=; b=nzUuF6XWBAAEJv2EiwpB2nTGwgkzwCx5gptCwn4iSMnclYy5adohhcbvsUUX7Bn0n9 Eo4TvmdpHQc6tgsB5qGFoiWZuUTrbxvlCj/cHXfo03kKXnusX+5n03MLCYDx3bDpKRSq tTH/iDH9ZU/EW10QQpI337yDR+EJqK2NbM9TDpw5AzgWlwUaq/17yjY0kyqpJKF49PBn yWR4YQq34HnrWjMgURq7QvtWC5BIux2OQe/JIKBMwZEaxAoBQp7tzYGdb0a9gZwHbWAM MeEeMk+tWv5UiDdgrL4amnZWUHeRD3NPu9vgPBGnyh/QSyVZwpxgbLtjPUv23EFNsm5n A0Pw== X-Forwarded-Encrypted: i=1; AJvYcCV8rcMh2QtTZCBaFl8G8T6xx0EChdbHkMkTjOji761NO7Z6EP1z2huYUJ9yb6m/vNJI9/aEVer+5K5sdP7x5VdzRzVt9rRt+NY+VND4 X-Gm-Message-State: AOJu0Yw1aLAVOb5dNNUsm2gMVvy/FdzcVxbgkjc3jBdum3QFXq8grQ9n +AkqNEW6P/Ki9oebYQKrhv3uQSOLkPmTAYMqbMjFvUpTZtm6UiAJ5lC4o4G0lh8bwJdY72dl26K dCwqX4JfvHS2jLix5GaQr8EXjNBkW44Aj8qo= X-Received: by 2002:a2e:9c92:0:b0:2d6:f793:3434 with SMTP id x18-20020a2e9c92000000b002d6f7933434mr513418lji.2.1711502770816; Tue, 26 Mar 2024 18:26:10 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: In-Reply-To: From: Zhaoyang Huang Date: Wed, 27 Mar 2024 09:25:59 +0800 Message-ID: Subject: Re: summarize all information again at bottom//reply: reply: [PATCH] mm: fix a race scenario in folio_isolate_lru To: Matthew Wilcox Cc: =?UTF-8?B?6buE5pyd6ZizIChaaGFveWFuZyBIdWFuZyk=?= , Andrew Morton , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , =?UTF-8?B?5bq357qq5ruoIChTdGV2ZSBLYW5nKQ==?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Mar 26, 2024 at 8:21=E2=80=AFPM Matthew Wilcox wrote: > > On Tue, Mar 26, 2024 at 05:06:55PM +0800, Zhaoyang Huang wrote: > > 1. Thread_readahead remove the folio from page cache and drop 2 refcnt > > by readahead_folio & filemap_remove_folio(get rid of the folios which > > failed to launch IO during readahead) > > refcnt =3D=3D 0, PG_lru =3D=3D true, PG_lock =3D=3D true > > read_pages > > ... > > folio =3D readahead_folio > > > > ********For the folio which can not launch IO, we should NOT drop > > refcnt here??? replaced by __readahead_folio???********** > > folio_get > > filemap_remove_folio(folio) > > folio_unlock > > > > folio_put > > Ignoring any other thread, you're basically saying that there's a > refcount imbalance here. Which means we'd hit an assert (that folio > refcount went below zero) in the normal case where another thread wasn't > simultaneously trying to do anything. Theoretically Yes but it is rare in practice as aops->readahead will launch all pages to IO under most scenarios. read_pages aops->readahead[1] .. while (folio =3D readahead_folio)[2] filemap_remove_folio IMO, according to the comments of readahead_page, the refcnt represents page cache dropped in [1] makes sense for two reasons, '1. The folio is going to do IO and is locked until IO done;2. The refcnt will be added back when found again from the page cache and then serve for PTE or vfs' while it doesn't make sense in [2] as the refcnt of page cache will be dropped in filemap_remove_folio * Context: The page is locked and has an elevated refcount. The caller * should decreases the refcount once the page has been submitted for I/O * and unlock the page once all I/O to that page has completed. * Return: A pointer to the next page, or %NULL if we are done.