Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp20810300rwd; Thu, 29 Jun 2023 07:18:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlG/HTRWYJyTaHQMK+W7HBGnV+bjqQA33SSLf7De9YdZ9Piprsvnqudl4vTAd3ZaUHXw4JRg X-Received: by 2002:a17:90a:b397:b0:263:5c78:4b63 with SMTP id e23-20020a17090ab39700b002635c784b63mr1120481pjr.45.1688048321896; Thu, 29 Jun 2023 07:18:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688048321; cv=none; d=google.com; s=arc-20160816; b=sQS56FDtIWocvwPrCkoNCnsqfPt4qa7is0tcmCMP81R9UXhixLPA629Rh617CSKRhz d5GvC5UGpr7ki9KGzR/bitBqZ2mnj/7SQRYSgDcKwGN/izTyiP+szmJ12ilcGewj/Nto yURAtdiXmPvMIxCCqQlDm9m8Cghw2pxfKiPqcF2DNYkdWmiGmLkNhHaX4YS6RXqcuLDa p6LxT2s3z85H/XaN6KptH6VtygXwDFlI22GmMLA752117fc1ZEE7PMWuJQO72GUj7tly DFOt4MxH7v5uZB0Y/ZZTtgXotxKOL95c5OYYR+JEXwwb7fklhszgE34y/MfK+TGrlWio F3xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=LrYbdcM0evC7Xy9CDimNEkxtdbpvB/BFhHVZyMGsjWc=; fh=lswiSFrYMnmLdOMoF+U2K6sm/5lUvTl+zEs3reRu9qA=; b=SEZYabPjElX2Og8VdvS5/vc8LyMDfN5jkri2xoVwLRyT9pZWSm2qOduy1KJEU0yo8R 2swvitw2PQqnly+CwGzlVVPnxsuM95Bp94mMTwsbGt6fK1P++8c+3MF4OwyTyWb2A8/a 3L7FpgzW49WhaBOE9QpYkD5N2msc9gss5R9M39GiRIQ1CG0nw4FO/yqLWtFsJdhNTQO2 Ys3uWV3LUQW6uXAB8SBHotXnpwb7KxuhFMSfJvpn2x1y260UGkEaeN7yit0EBPJ8fyD7 eb5w4JBdxgwY1FijOGR2UnE/5iA33gWRJgQ1SUYfZ04UtHdqfwIeJ0FT/a3u+dfZXMtk ardw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b="qV8F6si/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n6-20020a17090a9f0600b002631de09798si4861627pjp.53.2023.06.29.07.18.23; Thu, 29 Jun 2023 07:18:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b="qV8F6si/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232180AbjF2OAi (ORCPT + 99 others); Thu, 29 Jun 2023 10:00:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232161AbjF2OAe (ORCPT ); Thu, 29 Jun 2023 10:00:34 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B74241BD3; Thu, 29 Jun 2023 07:00:31 -0700 (PDT) Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35TDvSCY018330; Thu, 29 Jun 2023 13:59:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=pp1; bh=LrYbdcM0evC7Xy9CDimNEkxtdbpvB/BFhHVZyMGsjWc=; b=qV8F6si/hA4BMAclDXBQy7EBDubLFaV1IUaBMl1NIzccoj5zCV2u77w6NVMJFtkznkr7 ln1Oo/k2hNHfVuzudYvAvWMvXEoTFkxnXEBzShSU0D6WY/Cz2rBjy0HfxEbpc2zr6fmP eyeTGi/rLL1r1v/YRHvRsaWNFz6ptKjc1e2SbKrtxoqecgrANt4d9MN3C6N2f40/G59v 8s53SGXTAAegChcxiBTp/H1hMkYuiyIemVNXovvrZxVX9xW/puzk/H9OmrdYihtTMFXI BxoprZF/nsWn8XGRF24lWPl4TyTd2X1b9IT+NYD+e9N4ZAskKqxAzZbLBGlbHonfl8li /A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rhba183ms-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 29 Jun 2023 13:59:20 +0000 Received: from m0353725.ppops.net (m0353725.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35TDvdpg018759; Thu, 29 Jun 2023 13:59:19 GMT Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rhba183gk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 29 Jun 2023 13:59:18 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35T5nCVI014922; Thu, 29 Jun 2023 13:59:16 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma01fra.de.ibm.com (PPS) with ESMTPS id 3rdr452hpd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 29 Jun 2023 13:59:16 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35TDxCmc56885746 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 29 Jun 2023 13:59:12 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9F48C20043; Thu, 29 Jun 2023 13:59:12 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4EA7020040; Thu, 29 Jun 2023 13:59:09 +0000 (GMT) Received: from li-008a6a4c-3549-11b2-a85c-c5cc2836eea2.ibm.com (unknown [9.171.2.247]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTPS; Thu, 29 Jun 2023 13:59:09 +0000 (GMT) Date: Thu, 29 Jun 2023 15:59:07 +0200 From: Alexander Gordeev To: Gerald Schaefer Cc: Hugh Dickins , Andrew Morton , Vasily Gorbik , Mike Kravetz , Mike Rapoport , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Suren Baghdasaryan , Qi Zheng , Yang Shi , Mel Gorman , Peter Xu , Peter Zijlstra , Will Deacon , Yu Zhao , Alistair Popple , Ralph Campbell , Ira Weiny , Steven Price , SeongJae Park , Lorenzo Stoakes , Huang Ying , Naoya Horiguchi , Christophe Leroy , Zack Rusin , Jason Gunthorpe , Axel Rasmussen , Anshuman Khandual , Pasha Tatashin , Miaohe Lin , Minchan Kim , Christoph Hellwig , Song Liu , Thomas Hellstrom , Russell King , "David S. Miller" , Michael Ellerman , "Aneesh Kumar K.V" , Heiko Carstens , Christian Borntraeger , Claudio Imbrenda , Jann Horn , Vishal Moola , Vlastimil Babka , linux-arm-kernel@lists.infradead.org, sparclinux@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2 07/12] s390: add pte_free_defer() for pgtables sharing page Message-ID: References: <54cb04f-3762-987f-8294-91dafd8ebfb0@google.com> <20230628211624.531cdc58@thinkpad-T15> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230628211624.531cdc58@thinkpad-T15> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: YMCVI8WX38wPGVoSaafWaumxPTpPmIfa X-Proofpoint-ORIG-GUID: BptJCD1qhVG-ySwo39DLjqgVEpX_NEnC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-29_03,2023-06-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 bulkscore=0 impostorscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 clxscore=1011 mlxscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306290122 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 28, 2023 at 09:16:24PM +0200, Gerald Schaefer wrote: > On Tue, 20 Jun 2023 00:51:19 -0700 (PDT) > Hugh Dickins wrote: Hi Gerald, Hugh! ... > @@ -407,6 +445,88 @@ void __tlb_remove_table(void *_table) > __free_page(page); > } > > +#ifdef CONFIG_TRANSPARENT_HUGEPAGE > +static void pte_free_now0(struct rcu_head *head); > +static void pte_free_now1(struct rcu_head *head); What about pte_free_lower() / pte_free_upper()? ... > +void pte_free_defer(struct mm_struct *mm, pgtable_t pgtable) > +{ > + unsigned int bit, mask; > + struct page *page; > + > + page = virt_to_page(pgtable); > + if (mm_alloc_pgste(mm)) { > + /* > + * TODO: Do we need gmap_unlink(mm, pgtable, addr), like in > + * page_table_free_rcu()? > + * If yes -> need addr parameter here, like in pte_free_tlb(). > + */ > + call_rcu(&page->rcu_head, pte_free_pgste); > + return; > +} > + bit = ((unsigned long)pgtable & ~PAGE_MASK) / (PTRS_PER_PTE * sizeof(pte_t)); > + > + spin_lock_bh(&mm->context.lock); > + mask = atomic_xor_bits(&page->_refcount, 0x15U << (bit + 24)); This makes the bit logic increasingly complicated to me. What if instead we set the rule "one bit at a time only"? That means an atomic group bit flip is only allowed between pairs of bits, namely: bit flip initiated from ----------- ---------------------------------------- P <- A page_table_free(), page_table_free_rcu() H <- A pte_free_defer() P <- H pte_free_half() In the current model P bit could be on together with H bit simultaneously. That actually brings in equation nothing. Besides, this check in page_table_alloc() (while still correct) makes one (well, me) wonder "what about HH bits?": mask = (mask | (mask >> 4)) & 0x03U; if (mask != 0x03U) { ... } By contrast, with "one bit at a time only" policy every of three bits effectevely indicates which state a page half is currently in. Thanks!