Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2520595pxp; Mon, 21 Mar 2022 23:24:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgULDgE3IrYCj4QT6LzhaJh2vbT0oCppKuSVb5X4RXp9Z9jSTBXJkt7uIk63zMRgYvnUAz X-Received: by 2002:a63:f10c:0:b0:382:623b:3bb9 with SMTP id f12-20020a63f10c000000b00382623b3bb9mr9732366pgi.97.1647930291134; Mon, 21 Mar 2022 23:24:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647930291; cv=none; d=google.com; s=arc-20160816; b=tx79T/YPdWpeat1ZzVy3kf6p/N3lGWRuebgJJfo/ubD/m5NnbnCYhH9oswayj0z9kY ZhqMdjL6GtbM/7dfd1d7NMocDqCWUSJE079J0wYk3ZdHSmV4+k3WSoWKjKRD+rPvEXhq d+Io8dE0ngawpq8ZPRqBdhh031saCX66rhYg+0xN36LZGRhrxT6gcmS7LPSRn9jo1snr yVtXgVuFj1jrmvCTP1nyvG7hnqARZsi/DzChWTobwajw0R3dPMXshdII0e8aFGMk5rnP xMQrXrJUVvsi9LEdciGC0rm+U4RGHZ/CmExVh/CBmunWbsufMH5aELFhCKrX8b2SB1X8 HmWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=qVziKtonTIkNbV/B71HuGD9fXJjRE/zSA9pL7FZgyn4=; b=lpKAftPVdKZi52yUzilCwRD4YO/3UdMUXcH58nv53fqITIt+K6RAUyhHbBR5l5VT4I bcSYqIhgwt0/UPUlKY9aw0Cx4mA1LhgXe1rBlzhOcIvAYDiYHwIgp6feWV06AP/yI78M RbtXMGM7h3U3bVLFthy1eLx5kzr7BlC9+xRdWnlsRzYvWvRwpi/dCngFop2nUEKAPvwv eRZ4HD2zQqCJP7PlROm3ga0xM0s8A5ZQVKEB8IyAabVLDu0At05bb8SxTUHvXriNj1d4 OFd9mACG5Gj+YkEgVPl4FSIN8aiNAexfi8WILCyhd+wQ+9PkR2VY1ISJiTQqI/kKDf5q c92A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rWG3R5qt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id iq2-20020a17090afb4200b001c7370fb6cfsi1273963pjb.112.2022.03.21.23.24.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 23:24:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rWG3R5qt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CDF1F22524; Mon, 21 Mar 2022 22:56:44 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236842AbiCVF5a (ORCPT + 99 others); Tue, 22 Mar 2022 01:57:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236882AbiCVF51 (ORCPT ); Tue, 22 Mar 2022 01:57:27 -0400 Received: from mail-ua1-x92b.google.com (mail-ua1-x92b.google.com [IPv6:2607:f8b0:4864:20::92b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADC432A273 for ; Mon, 21 Mar 2022 22:55:57 -0700 (PDT) Received: by mail-ua1-x92b.google.com with SMTP id a28so6601192uaf.7 for ; Mon, 21 Mar 2022 22:55:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=qVziKtonTIkNbV/B71HuGD9fXJjRE/zSA9pL7FZgyn4=; b=rWG3R5qtX3GucWwH/rM7jmJOCfVi1T2dvoGI6lKrW+Kouh7f4j1XUU0D9xwMNzNHOo dCnFw11acEpDzgxXIxKkr9JUAeKCz8hqSXKb3u0uMF7Ds2qDxH5HRCPUWjY0KheQt5ys dVCRYr3EJc33+LNjGUoQn+m6pD7G2XugAlmc+o/BOLG9KKf5ii9XOblcuHbqLUrW6C2r GkCpVUgz7ej3LX9oiCj8+FQoXwEuWTYiR+JgnaNATpY/mb+E+UWRf4BX71w153S3JWuS iQ7HJcjF4rNDbIqhlJtMxxMFzQ46p2okOvFx3s6tVJ5pGcqFH90djo0dIcO0q1QlI5zX AfVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qVziKtonTIkNbV/B71HuGD9fXJjRE/zSA9pL7FZgyn4=; b=TEjCYf84nBFzxYCKl/M8n4r92fs5COluT3/MMVQbzmNkwl0eHrGfZAKbLOtOLYqFxs gHBCNfWSZdiNu4hsyDB5jHFhy1EWHpPnRZDA3ZWxI/C7VrkoPoLumkoM6FbcDvYr4u/8 Eqvh/VvEiUfCuy2ajgjhlRc/AsX9ZjLFoG5hwLPqOc846VEcu5wvNBMqf+wO6u+NKC7J kgMPRbflm8mubQdoAz/gM+bdCx5GfyehE1dbJDYi13E3OvKLwPJ1PPP3eA3ZZaYDulDH iT19jpJBULmTTGSyakWpFqar6PxRsV8R5hpke7O+VisUrbvb9Iq0q6S4f/ZPDnn/2IlJ g9XQ== X-Gm-Message-State: AOAM531xzMZ3/XYFUC01NlAG7XqmvNna+U6XrMiTiNAQUL5FF8EQUL2H KibF8khuLwsr2myEhWPkvQmkvAgOxEy3IpnwroB+Fg== X-Received: by 2002:ab0:77d5:0:b0:352:42d7:88c2 with SMTP id y21-20020ab077d5000000b0035242d788c2mr8221502uar.1.1647928556608; Mon, 21 Mar 2022 22:55:56 -0700 (PDT) MIME-Version: 1.0 References: <20220309021230.721028-1-yuzhao@google.com> <20220309021230.721028-7-yuzhao@google.com> <877d8m7e1x.fsf@linux.ibm.com> In-Reply-To: <877d8m7e1x.fsf@linux.ibm.com> From: Yu Zhao Date: Mon, 21 Mar 2022 23:55:45 -0600 Message-ID: Subject: Re: [PATCH v9 06/14] mm: multi-gen LRU: minimal implementation To: "Aneesh Kumar K.V" Cc: Andrew Morton , Linus Torvalds , Andi Kleen , Catalin Marinas , Dave Hansen , Hillf Danton , Jens Axboe , Jesse Barnes , Johannes Weiner , Jonathan Corbet , Matthew Wilcox , Mel Gorman , Michael Larabel , Michal Hocko , Mike Rapoport , Rik van Riel , Vlastimil Babka , Will Deacon , Ying Huang , Linux ARM , "open list:DOCUMENTATION" , linux-kernel , Linux-MM , Kernel Page Reclaim v2 , "the arch/x86 maintainers" , Brian Geffon , Jan Alexander Steffens , Oleksandr Natalenko , Steven Barrett , Suleiman Souhlal , Daniel Byrne , Donald Carr , =?UTF-8?Q?Holger_Hoffst=C3=A4tte?= , Konstantin Kharlamov , Shuang Zhai , Sofia Trinh , Vaibhav Jain Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 Mon, Mar 21, 2022 at 11:27 PM Aneesh Kumar K.V wrote: > > Yu Zhao writes: > > > +static void inc_max_seq(struct lruvec *lruvec, unsigned long max_seq) > > +{ > > + int prev, next; > > + int type, zone; > > + struct lru_gen_struct *lrugen = &lruvec->lrugen; > > + > > + spin_lock_irq(&lruvec->lru_lock); > > + > > + VM_BUG_ON(!seq_is_valid(lruvec)); > > + > > + if (max_seq != lrugen->max_seq) > > + goto unlock; > > + > > + inc_min_seq(lruvec); > > Can this min seq update result in pages considered oldest become young. > ie, if we had seq value of 0 - 3 and we need ageing, the new min seq and > max_seq value will now become 1 - 4. What happens to pages in the > generation value 0 which was oldest generation earlier and is youngest > now. If anon pages are not reclaimable, e.g., no swapfile, they won't be scanned at all. So their coldness/hotness don't matter -- they don't need to be on lrugen->lists[] at all. If there is a swapfile but it's full, then yes, the inversion will happen. This can be handled by moving pages from the oldest generation to the tail of the second oldest generation, which maintains the LRU order. In fact, both were handled in the previous versions [1] [2]. They were removed in v6 for simplicity. [1] https://lore.kernel.org/linux-mm/20211111041510.402534-5-yuzhao@google.com/ [2] https://lore.kernel.org/linux-mm/20211111041510.402534-7-yuzhao@google.com/ > > +static int evict_folios(struct lruvec *lruvec, struct scan_control *sc, int swappiness) > > +{ > > + int type; > > + int scanned; > > + int reclaimed; > > + LIST_HEAD(list); > > + struct folio *folio; > > + enum vm_event_item item; > > + struct reclaim_stat stat; > > + struct mem_cgroup *memcg = lruvec_memcg(lruvec); > > + struct pglist_data *pgdat = lruvec_pgdat(lruvec); > > + > > + spin_lock_irq(&lruvec->lru_lock); > > + > > + scanned = isolate_folios(lruvec, sc, swappiness, &type, &list); > > + > > + if (try_to_inc_min_seq(lruvec, swappiness)) > > + scanned++; > > we are doing this before we shrink the page list. Any reason to do this before? We have isolated pages from lrugen->lists[], and we might have exhausted all pages in the oldest generations, i.e., lrugen->lists[min_seq] is now empty. Incrementing min_seq after shrink_page_list() is not wrong. However, it's better we do it ASAP so that concurrent reclaimers are less likely to see a stale min_seq and come here under the false impression that they'd make some progress. (Instead, they will go to the aging path and inc_max_seq() first before coming here.)