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 DFC44C7EE2A for ; Wed, 25 Jun 2025 20:47:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C3CD6B00AA; Wed, 25 Jun 2025 16:47:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 64D5E6B00AB; Wed, 25 Jun 2025 16:47:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 514EE6B00AC; Wed, 25 Jun 2025 16:47:54 -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 3F70D6B00AA for ; Wed, 25 Jun 2025 16:47:54 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E76DABB3D7 for ; Wed, 25 Jun 2025 20:47:53 +0000 (UTC) X-FDA: 83595109626.21.4BEA991 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf05.hostedemail.com (Postfix) with ESMTP id C0F87100002 for ; Wed, 25 Jun 2025 20:47:51 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=RHr5AWyT; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=nPS3ts6u; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=RHr5AWyT; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=nPS3ts6u; spf=pass (imf05.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750884472; 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=UZuuQVBAOjxFkwRxiQlkI49ia3QjY5cZKASUPO9GhxM=; b=teBKKZr9PvTYJoHbjLtAiQxRhL+HE6MxVkPyf+b8c6kHpcpVHhjc9giCmi8NITeqaJHZPB vanE1SpPyTugxOEdAOsb5+5F1ynmi0lU82QT/8kTg+DupWKmVM+iSWES+UF20ecT4q77Mr IXgwc1AhOJn3unkltBMjLh1jsFWwJ3U= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=RHr5AWyT; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=nPS3ts6u; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=RHr5AWyT; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=nPS3ts6u; spf=pass (imf05.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750884472; a=rsa-sha256; cv=none; b=v5Mzn4Cg9bIcKaMSyxMXXFEzqYCzRqnCIXOE1TCUSPq/plfJn929Ch5kdvvrlFYfg47RDd nwbaEgZIydyBBu+YoVdzbr7LCGHujX4tkqzy0TNEg/RQ9dgeooeIxi/8/CeGQ/FunGNrFg 8ZaMYlV8MggZF3LX6GqI0m8wWyXzeQQ= Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 477931F399; Wed, 25 Jun 2025 20:47:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1750884470; h=from:from:reply-to: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=UZuuQVBAOjxFkwRxiQlkI49ia3QjY5cZKASUPO9GhxM=; b=RHr5AWyTogjk7wDUHEicPyxGiIs/pm55BRPKvkL9SDhFgebicB16M30BYwG/uRn5djaUZP BmrKSYr2hSCgpXnLFVLKOwAWy7laZjQHjgBU7j38J3QwbIIoMJ2b3oUH59jvQBl/U3+fwW Q1wojKxyt/6ercQ10GWe8lu6Ung+z2Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1750884470; h=from:from:reply-to: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=UZuuQVBAOjxFkwRxiQlkI49ia3QjY5cZKASUPO9GhxM=; b=nPS3ts6uFxPnl16PEip4jBEtKbL42bAEZKxyJJdS2mzduTsk97QrxfkBn6+47oIudy1znn eFT8NPcAx5XrVOAg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1750884470; h=from:from:reply-to: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=UZuuQVBAOjxFkwRxiQlkI49ia3QjY5cZKASUPO9GhxM=; b=RHr5AWyTogjk7wDUHEicPyxGiIs/pm55BRPKvkL9SDhFgebicB16M30BYwG/uRn5djaUZP BmrKSYr2hSCgpXnLFVLKOwAWy7laZjQHjgBU7j38J3QwbIIoMJ2b3oUH59jvQBl/U3+fwW Q1wojKxyt/6ercQ10GWe8lu6Ung+z2Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1750884470; h=from:from:reply-to: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=UZuuQVBAOjxFkwRxiQlkI49ia3QjY5cZKASUPO9GhxM=; b=nPS3ts6uFxPnl16PEip4jBEtKbL42bAEZKxyJJdS2mzduTsk97QrxfkBn6+47oIudy1znn eFT8NPcAx5XrVOAg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id CEEDF13485; Wed, 25 Jun 2025 20:47:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id AL0uL3VgXGi8fwAAD6G6ig (envelope-from ); Wed, 25 Jun 2025 20:47:49 +0000 Date: Wed, 25 Jun 2025 22:47:40 +0200 From: Oscar Salvador To: David Hildenbrand Cc: Andrew Morton , Muchun Song , Peter Xu , Gavin Guo , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/5] mm,hugetlb: Sort out folio locking in the faulting path Message-ID: References: <20250620123014.29748-1-osalvador@suse.de> <20250620123014.29748-3-osalvador@suse.de> <35b03911-74c3-4626-aaa8-4c331c086f8f@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: C0F87100002 X-Stat-Signature: f49xpkw8ouwts7jy4947uh3s6fuak4uu X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1750884471-96608 X-HE-Meta: U2FsdGVkX1+daAGeuMVmLeUZPsNuUvlNmCjtqwGyLYueJHoyZb6ybPHDQ09iGXs4taJ5D7wgUOLcShjcGfU0lxCkkv0UJ/Hr3m7kFpv3jWYAuB3wbe2Qi2t4Ck0EYeskG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V9DiBt+WWbomM/ZRxjg8SusHreoJEAjw0Bm/TkNoDZa85Ywb8= 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, Jun 25, 2025 at 09:47:00AM +0200, Oscar Salvador wrote: > On Mon, Jun 23, 2025 at 04:11:38PM +0200, David Hildenbrand wrote: > > > @@ -6801,13 +6810,24 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, > > > /* Fallthrough to CoW */ > > > } > > > - /* hugetlb_wp() requires page locks of pte_page(vmf.orig_pte) */ > > > - folio = page_folio(pte_page(vmf.orig_pte)); > > > - folio_lock(folio); > > > - folio_get(folio); > > > - > > > if (flags & (FAULT_FLAG_WRITE|FAULT_FLAG_UNSHARE)) { > > > if (!huge_pte_write(vmf.orig_pte)) { > > > + /* > > > + * Anonymous folios need to be lock since hugetlb_wp() > > > + * checks whether we can re-use the folio exclusively > > > + * for us in case we are the only user of it. > > > + */ > > > > Should we move that comment to hugetlb_wp() instead? And if we are already > > doing this PTL unlock dance now, why not do it in hugetlb_wp() instead so we > > can simplify this code? > > Yes, probably we can move it further up. > Let me see how it would look. So, I've been thinking about this, and I'm not so sure. By default, the state of the folio in hugetlb_no_page and hugetlb_fault is different. hugetlb_no_page() has the folio locked already, and hugetlb_fault() hasn't, which means that if we want to move this further up, 1) hugetlb_no_page() would have to unlock the folio to then lock it in hugetlb_wp() in case it's anonymous or 2) pass a parameter to hugetlb_wp() to let it know whether the folio is already locked. Don't really like any of them. Case 1) seems suboptimal as right now (with this patch) we only unlock the folio in !anon case in hugetlb_no_page(). If we want to move the 'dance' from hugetlb_fault() to hugetlb_wp(), we'd have to unlock and then lock it again. -- Oscar Salvador SUSE Labs