Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp782110ybz; Fri, 17 Apr 2020 09:57:01 -0700 (PDT) X-Google-Smtp-Source: APiQypJRGxTKkD2PK27IdyefrelumozK3MTgqWhGF1Z0JV3eTJrC8/Q5ern+nB8+RjV3lyl7qOtn X-Received: by 2002:a50:d942:: with SMTP id u2mr4038478edj.116.1587142620807; Fri, 17 Apr 2020 09:57:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587142620; cv=none; d=google.com; s=arc-20160816; b=RiMuxbXs71+cyt8cpjMKJApK3TPp14l5ekb+veiCVRjxIdlZC6qf33Z6Jfv/fX00xs BodqqdF/8Z3rZYwRMhzxGa/c95eDTtGKej+bIfarLpIuoRflOSj81kUpIjD2pboSP6wV 8vP85w5QyYwfOXfJBtA/fNAnuRyUCVP0GUhVCPjabDJkCuduRLgBZ1tq98teif1cUTpU 4Tt93MoPchmiVNnotLHECN0rfKxTT/CaqmVakw0eR89b6G5Boye6mO/I3R9DpkOPoH0j j/krqk331sXt4cY7alOYF2iqlx8JuRQAxq6w4Oh9A4Ebz3+x6nzt0xh5zjUNEKlHjYrj wpxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=TUjmNpTkRUHjFQU3sZOC9N/p+7Qi1HmP8jwrqOUVxtQ=; b=Z6deqVjT1dZ0AqV6P+a6zysHqbmMFSdfjm4VGKLnO+AGBbgo7DrSCDWuh014VgLhDA RSp8gEWmVMJSTWycMls9vng9oBZccv5e9Lh/EBdorHs3/m07QUU0Bun0gXij9UBAmlGB 2h2sYA5Uqm/ZezZmYH3jUfO4tYMZua33XPbIUGKBtWL+tkkEvOIspnPz9pXrftFHMxm9 wFPpilJBXL3DELX7huPg9YeCoJtdjiiAyNEOoKfhmGtVaXgY1CkiCoAH2dHYRv7EiCoq mK+Diwqd/W5D0ho0prhGmB9YDlcgamcAphHylq9/hMmuaWOc3R+Cp2TWUoWfAoni7U6x nKfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=ddRbaJFy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e5si14678212edc.160.2020.04.17.09.56.37; Fri, 17 Apr 2020 09:57:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=ddRbaJFy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727123AbgDQQy4 (ORCPT + 99 others); Fri, 17 Apr 2020 12:54:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726105AbgDQQyz (ORCPT ); Fri, 17 Apr 2020 12:54:55 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 309BBC061A0C for ; Fri, 17 Apr 2020 09:54:55 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id l11so2367633lfc.5 for ; Fri, 17 Apr 2020 09:54:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=TUjmNpTkRUHjFQU3sZOC9N/p+7Qi1HmP8jwrqOUVxtQ=; b=ddRbaJFypSDnHxxSGThJ4HEJ2KvJRLqKBIxb9wqT/VQT/s5eBK5IpwBn96NG4HtT7t kFH8mrSVHxTuKeOeAiSYdQ81Dw98+WKMraTxm335md7MJqUPYvX17YMDw7zaQYY0PD4A 2oSyQ/KPy3LJczhml0FWU+O5NYXqcMljE94r1H+c9fYoHd+b2oNMZ+xHC+yRwBdE8obM ufbss3EZSs+1TL4/e7nNhsRcD3ik56iMIVfAMyo4s4aveac8VXDZvn/K1uoqL3dEHwN/ flRJSPWZ22wXUCLfkUaOG7kPbOtffAuMTSFASSA7stWu8UfnLXt3vTRMAzPDOius10l6 VwOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=TUjmNpTkRUHjFQU3sZOC9N/p+7Qi1HmP8jwrqOUVxtQ=; b=Uyw8eleQnXlXo5iz3jOmAZji6qRuf7ySkCdOGE78yYy3RA+TzoqW60xYNpEWsPdLd6 7iNw279N7YaedJAH0WrvqVnspPF8i0L5XqjPBqu1QNdHm8r9CS4me2T8SyS1AnjtPNTI WgDt0wlf3eHY6zf/Koc1DN5l08ol27YDDygNYgcR7r9e68D/xoV3dIv4778rB5qUWz8O iZYfYpHSAvf4bBLqBv/Kpn5knPEU30I1yH8X78+9jjE84zJ6u7f5U0/bJzgcyfo8IfdN mswPsfhFnmlcyyDypEcJywiP+hd4Ajc5Ed7Q+1fGAt6JPTXZxkRrMbXuBepYHR8NrBO7 6M1A== X-Gm-Message-State: AGi0PubKdiU7f3KvBM6e4iGZ7bY1pI5g6J2o+UHZukSkBREbdFUPFDGi ChPyIzv58nmXZak/vfhPWLwqWA== X-Received: by 2002:ac2:522e:: with SMTP id i14mr2628298lfl.140.1587142492816; Fri, 17 Apr 2020 09:54:52 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id e8sm16891517lja.3.2020.04.17.09.54.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Apr 2020 09:54:52 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id A16F9100AEA; Fri, 17 Apr 2020 19:54:51 +0300 (+03) Date: Fri, 17 Apr 2020 19:54:51 +0300 From: "Kirill A. Shutemov" To: Peter Zijlstra Cc: "Kirill A. Shutemov" , Dave Hansen , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH, RFC] x86/mm/pat: Restore large pages after fragmentation Message-ID: <20200417165451.y2mj7ta3rqtxjcdc@box> References: <20200416213229.19174-1-kirill.shutemov@linux.intel.com> <20200417154714.GI20730@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200417154714.GI20730@hirez.programming.kicks-ass.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 17, 2020 at 05:47:14PM +0200, Peter Zijlstra wrote: > On Fri, Apr 17, 2020 at 12:32:29AM +0300, Kirill A. Shutemov wrote: > > +static void cpa_restore_large_pages(struct cpa_data *cpa, > > + struct list_head *pgtables) > > +{ > > + unsigned long start, addr, end; > > + int i; > > + > > > + start = __cpa_addr(cpa, 0); > > + end = start + PAGE_SIZE * cpa->numpages; > > + > > + for (addr = start; addr >= start && addr < end; addr += PUD_SIZE) > > + restore_large_pages(addr, pgtables); > > Isn't that loop slightly broken? > > Consider: > > s e > |---------|---------|---------|---------| > a0 a1 a2 a3 > > Where s,e are @start,@end resp. and a# are the consecutive values of > @addr with PUD sized steps. > > Then, since a3 is >= @end, we'll not take that iteration and we'll not > try and merge that last PUD, even though we possibly could. One fix is > to truncate @start (and with that @addr) to the beginning of the PUD. ... or round_up() end. I'll fix it. > Also, I'm afraid that with my proposal this loop needs to do PMD size > steps. In that regard your version does make some sense. But it is > indeed less efficient for small ranges. > > One possible fix is to pass @start,@end into the > restore/reconstruct/collapse such that we can iterate the minimal set of > page-tables for each level. Yeah, I'll rework it. I just realized I missed TLB flush: we need to flush TLB twice here. First to get rid of all TLB entires for change we've made (before reconstruction) and then the second time to get rid of small page TLB entries. That's unfortunate. -- Kirill A. Shutemov