Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753677AbdFPNgH (ORCPT ); Fri, 16 Jun 2017 09:36:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36392 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753326AbdFPNgE (ORCPT ); Fri, 16 Jun 2017 09:36:04 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 81CBFC04B950 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=aarcange@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 81CBFC04B950 Date: Fri, 16 Jun 2017 15:36:00 +0200 From: Andrea Arcangeli To: "Kirill A. Shutemov" Cc: Andrew Morton , Vlastimil Babka , Vineet Gupta , Russell King , Will Deacon , Catalin Marinas , Ralf Baechle , "David S. Miller" , "Aneesh Kumar K . V" , Martin Schwidefsky , Heiko Carstens , linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner Subject: Re: [PATCHv2 1/3] x86/mm: Provide pmdp_establish() helper Message-ID: <20170616133600.GE11676@redhat.com> References: <20170615145224.66200-1-kirill.shutemov@linux.intel.com> <20170615145224.66200-2-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170615145224.66200-2-kirill.shutemov@linux.intel.com> User-Agent: Mutt/1.8.3 (2017-05-23) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 16 Jun 2017 13:36:04 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1121 Lines: 36 Hello Krill, On Thu, Jun 15, 2017 at 05:52:22PM +0300, Kirill A. Shutemov wrote: > +static inline pmd_t pmdp_establish(pmd_t *pmdp, pmd_t pmd) > +{ > + pmd_t old; > + > + /* > + * We cannot assume what is value of pmd here, so there's no easy way > + * to set if half by half. We have to fall back to cmpxchg64. > + */ > + { > + old = *pmdp; > + } while (cmpxchg64(&pmdp->pmd, old.pmd, pmd.pmd) != old.pmd); > + > + return old; > +} I see further margin for optimization here (although it's only for PAE x32..). pmd is stable so we could do: if (!(pmd & _PAGE_PRESENT)) { cast to split_pmd and use xchg on pmd_low like native_pmdp_get_and_clear and copy pmd_high non atomically } else { the above cmpxchg64 loop } Now thinking about the above I had a second thought if pmdp_establish is the right interface and if we shouldn't replace pmdp_establish with pmdp_mknotpresent instead to skip the pmd & _PAGE_PRESENT check that will always be true in practice, so pmdp_mknotpresent will call internally pmd_mknotpresent and it won't have to check for pmd & _PAGE_PRESENT and it would have no cons on x86-64.