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 B2618E6FE57 for ; Fri, 22 Sep 2023 15:38:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E333F6B02D7; Fri, 22 Sep 2023 11:38:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DE24B6B02DA; Fri, 22 Sep 2023 11:38:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C82B86B02DB; Fri, 22 Sep 2023 11:38:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B63E06B02D7 for ; Fri, 22 Sep 2023 11:38:58 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 843B680F05 for ; Fri, 22 Sep 2023 15:38:58 +0000 (UTC) X-FDA: 81264641556.10.176A710 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 063C01C0036 for ; Fri, 22 Sep 2023 15:38:55 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SGdFk1b7; spf=pass (imf20.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695397136; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=28YK1yWDhsvGzgSgmFKM5KSBJsEoW2Mh43BzpB68BbM=; b=mBfVCpcZiwSWews4kl3llQ49zQg+u1ytfkNFM6IZeAAdTOFZ7E+J0XlW2r5dbYFbK1MV4g 3BFuAZ+Okp5ffHF7cA1SeM0AMiVcBSrYUkVrVHQU8sETXIXc+qk6I94oQYcZn/4nzWMYzs K1Q3D5GnRXuAxs3SZHEs4bSqd5bCncY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SGdFk1b7; spf=pass (imf20.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695397136; a=rsa-sha256; cv=none; b=NRYZJWFPWDr+8HKbiBQ4insc+hdkzNndzCsFMJpq02i+qXKiz0JWvI6DG2ozgSQCgDjKNQ XnLYqS1LaLcwpd8fBBD4B+kEF/9RNOI0nYOknhM2N8mk56Z+mS/3L2cu+9xj7yuAfXRmCT K/DLi9159+cn9ov3BRa3svqvm8dm3b8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695397135; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=28YK1yWDhsvGzgSgmFKM5KSBJsEoW2Mh43BzpB68BbM=; b=SGdFk1b72tnrFq0c0QtsrArKU71urD1aLMvRMm76RAIusvysx0Uxp9Rv15GwzJTNUSTZkX cN6tQLcvbXu4OlSgQWDXTipszgxqsotgYyJfhaIkf5tuFecIp390NeslMFsyS9j8X2An1d Lyal2UPpxd1fbMFrSvB9I0J3utTH/Ds= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-624-WQNW6lfDNquKcawNmzpSZw-1; Fri, 22 Sep 2023 11:38:52 -0400 X-MC-Unique: WQNW6lfDNquKcawNmzpSZw-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-403ca0e2112so17351855e9.0 for ; Fri, 22 Sep 2023 08:38:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695397131; x=1696001931; h=content-transfer-encoding:subject:organization:in-reply-to :content-language:references:cc:to:from:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=28YK1yWDhsvGzgSgmFKM5KSBJsEoW2Mh43BzpB68BbM=; b=UYaipvh67rVeW+9aKkAFHmmHk5ZTy8TzLNH/su8vqrCaEeg8Vajimqlaj1jM5gWHgR 0ZhQbzdfeCaXJZBzrYmoy7gcjiH0uSbhzYRJBvG09PgvfNOBqn/v3IYiEAjJ/NxmTUji q8Bpv32/OO/+e19UQKb/udpj4OQtLF4bDPN3tCYlHuTkOUZM4cV16VmgUX7V7kX2KUGf QRZZgWpPVJdb/RNvk4MJc5jwZ4QWYMNGypPVljPwc5IdnPxY5jW97ET9nzFLXRqPBTma knrAmR2EtdBTKizpjGdybGkkZoVE7WUbzor6biA2MdFC46RYRtPVsWmpY6tkPZEanmm/ lWrQ== X-Gm-Message-State: AOJu0Yxj1l4gT035WLtGw0vI8/fuP728vXt8HUHZga6UVDveguWfXZfV MxpFvUDeiRDtjodyqo8yj0XqimpWmCdPp2ZtskttfTWjMboW8nG9VN9Ju8+1KQYfcjLNmotb+kt v2E8wwPkI1Mg= X-Received: by 2002:a05:6000:1cc4:b0:321:68fa:70aa with SMTP id bf4-20020a0560001cc400b0032168fa70aamr50820wrb.9.1695397131643; Fri, 22 Sep 2023 08:38:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFtnIOkmAt3qyian4WMHlSMv2Pq0c2znHPkEQSbVqQXXatSTUNIsXYfYNHYUP5Ouq7MoKz3dA== X-Received: by 2002:a05:6000:1cc4:b0:321:68fa:70aa with SMTP id bf4-20020a0560001cc400b0032168fa70aamr50781wrb.9.1695397131168; Fri, 22 Sep 2023 08:38:51 -0700 (PDT) Received: from ?IPV6:2003:cb:c71a:7100:dfaf:df8b:54b9:7303? (p200300cbc71a7100dfafdf8b54b97303.dip0.t-ipconnect.de. [2003:cb:c71a:7100:dfaf:df8b:54b9:7303]) by smtp.gmail.com with ESMTPSA id j3-20020a5d5643000000b0032167e49619sm4733853wrw.5.2023.09.22.08.38.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 22 Sep 2023 08:38:50 -0700 (PDT) Message-ID: Date: Fri, 22 Sep 2023 17:38:49 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 From: David Hildenbrand To: Stefan Roesch , kernel-team@fb.com Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, riel@surriel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20230918185816.1518366-1-shr@devkernel.io> <20230918185816.1518366-2-shr@devkernel.io> In-Reply-To: <20230918185816.1518366-2-shr@devkernel.io> Organization: Red Hat Subject: Re: [PATCH v2 1/4] mm/ksm: add "smart" page scanning mode X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 063C01C0036 X-Rspam-User: X-Stat-Signature: n1xxnneeymemetcmxrib1t5edwdrupek X-Rspamd-Server: rspam01 X-HE-Tag: 1695397135-29481 X-HE-Meta: U2FsdGVkX1/+Vnkfp4eiNBbxtvbxILdxOLw2zwnL69HJKco7vQvWmZ8FZtVht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hb43n9buTRKC/Kd71j3U4KExP/YMUQNVpTa2EvjDHjEjuoW+YxISqmyuD60KqEjA9cv1Et4+pOx78Mi1h1Y3vBAim8//KKgRGh7rKZt0fodRB/1jblD4UIuFKW55KJvg9Swnr6k/XJW7mzpom2wPSDUzL/9CcHh9nY8H6Ln1iYoC4cnsS9d3qMoucwuF+cj96LNFDK8YWYFjHBuFKzfZfp5sOlP6Vcw X-Bogosity: Ham, tests=bogofilter, spamicity=0.012106, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: > +typedef u8 rmap_age_t; > + > /** > * DOC: Overview > * > @@ -193,6 +195,8 @@ struct ksm_stable_node { > * @node: rb node of this rmap_item in the unstable tree > * @head: pointer to stable_node heading this list in the stable tree > * @hlist: link into hlist of rmap_items hanging off that stable_node > + * @age: number of scan iterations since creation > + * @skip_age: skip rmap item until age reaches skip_age > */ > struct ksm_rmap_item { > struct ksm_rmap_item *rmap_list; > @@ -212,6 +216,8 @@ struct ksm_rmap_item { > struct hlist_node hlist; > }; > }; > + rmap_age_t age; > + rmap_age_t skip_age; I *think* of you move that after "oldchecksum", the size of the struct might not necessarily increase. [...] > > +/* > + * Calculate skip age for the ksm page age. The age determines how often > + * de-duplicating has already been tried unsuccessfully. If the age is > + * smaller, the scanning of this page is skipped for less scans. > + * > + * @age: rmap_item age of page > + */ > +static unsigned int skip_age(rmap_age_t age) > +{ > + if (age <= 3) > + return 1; > + if (age <= 5) > + return 2; > + if (age <= 8) > + return 4; > + > + return 8; > +} > + > +/* > + * Determines if a page should be skipped for the current scan. > + * > + * @page: page to check > + * @rmap_item: associated rmap_item of page > + */ > +static bool should_skip_rmap_item(struct page *page, > + struct ksm_rmap_item *rmap_item) > +{ > + rmap_age_t age; > + > + if (!ksm_smart_scan) > + return false; > + > + /* > + * Never skip pages that are already KSM; pages cmp_and_merge_page() > + * will essentially ignore them, but we still have to process them > + * properly. > + */ > + if (PageKsm(page)) > + return false; > + > + /* > + * Smaller ages are not skipped, they need to get a chance to go > + * through the different phases of the KSM merging. > + */ Sorry, had to set some time aside to think this through. Wouldn't it be cleaner to just not rely on this overflow? Instead, we could track the page age (which we would freeze at U8_MAX) and simply track how much more often we are allowed to skip. Something like the following (which, I am sure, is completely broken, but should express what I have in mind) age = rmap_item->age; if (age != U8_MAX) rmap_item->age++; /* * Smaller ages are not skipped, they need to get a chance to go * through the different phases of the KSM merging. */ if (age < 3) return false; /* * Are we still allowed to skip? If not, then don't skip it * and determine how much more often we are allowed to skip next. */ if (!rmap_item->remaining_skips) { rmap_item->remaining_skips = skip_age(age); return false; } /* Skip this page. */ rmap_item->remaining_skips--; remove_rmap_item_from_tree(rmap_item); return true; Would that miss anything important? Was the overflow handling (and scanning more often one we overflow again IIUC) important? -- Cheers, David / dhildenb