Received: by 10.223.176.46 with SMTP id f43csp4016354wra; Tue, 23 Jan 2018 02:56:30 -0800 (PST) X-Google-Smtp-Source: AH8x226Ek3ohpA4KdEmwgIO3GUkzxYQ2az5rw1ykzUYq1hxKx9y6ZCUZo+1zIYBj4x7YI6v3n3MX X-Received: by 10.98.224.205 with SMTP id d74mr10324630pfm.56.1516704990770; Tue, 23 Jan 2018 02:56:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516704990; cv=none; d=google.com; s=arc-20160816; b=bP4y9CXInQ7/D5P+C9VZFTrp6IHre/K190wdiEbZ3dpXp+6CBoFMalj0Iu3MSZrH26 jympiC/E2l2nTsy2iP3urBpXBXiUPsrpHE7C7E9RQ7e997ciYldgWurW9o9HQ15qyXM5 lu8x8R0uz0Gl2AD78ZPvW125iTzYTKG8i+nW+EZq+12DbtO+inwn5OF+7cYpq0Ltga6x xh/5Lx5imwRrb+5T+EcyP68X2Huk5k4maBCW2f8hEGW8bdLcpWrxIPb3066UCUCKjBGz Bw456joDg96/zByq0eEEJTcynxerZYd5HxTozREZ7Rz9YyOcwgPOWlzTA205m37mBqQd wyKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:to:from:subject :dkim-signature:arc-authentication-results; bh=arUB+n4T9NiyjZHvAdD7/l94qJRQ8ZWWKV45IG7wnV8=; b=KJpQNl/t/aF8FJ47N5jxByo8+vgs+HLMfMLSo1xZz/IrDw04rbH9g1WucYdb7rjkTj gtXyV/gBUBXep4CXOZ36iIo/8EdJvcZH9RVNQhpKxAq0lat/m6xvwcmq+BJZmnBeU8uB 0nlD0SyhxUdg8SxsdYNyL+7vT1vgok3nGdVSweTmvLBMlghsEYTPbzYujmwmsQpesqWC puCxC8rxHHfRm6k+4LHpv2QU06m0ThADQIL5afmy0aoW/29/sIykKLD/KRhh8siDe4ci Q7+NdFXxDu2JHJz3zJOVbaAJZvqzHYTENx3ddCQP1akhjcf8ZNawAWr//jrFKhavdyNW VjdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=xG6aTo/W; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r8-v6si4553607pli.536.2018.01.23.02.56.16; Tue, 23 Jan 2018 02:56:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=xG6aTo/W; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751506AbeAWKzh (ORCPT + 99 others); Tue, 23 Jan 2018 05:55:37 -0500 Received: from forwardcorp1g.cmail.yandex.net ([87.250.241.190]:59461 "EHLO forwardcorp1g.cmail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751234AbeAWKzg (ORCPT ); Tue, 23 Jan 2018 05:55:36 -0500 Received: from smtpcorp1p.mail.yandex.net (smtpcorp1p.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b6:10]) by forwardcorp1g.cmail.yandex.net (Yandex) with ESMTP id B285F202C5; Tue, 23 Jan 2018 13:55:34 +0300 (MSK) Received: from smtpcorp1p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtpcorp1p.mail.yandex.net (Yandex) with ESMTP id B0CB56E40DEE; Tue, 23 Jan 2018 13:55:34 +0300 (MSK) Received: from unknown (unknown [2a02:6b8:0:40c:b4b7:f0f3:4b10:5639]) by smtpcorp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id XGjHUuXtF6-tYLSDkUB; Tue, 23 Jan 2018 13:55:34 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1516704934; bh=arUB+n4T9NiyjZHvAdD7/l94qJRQ8ZWWKV45IG7wnV8=; h=Subject:From:To:Date:Message-ID:In-Reply-To:References; b=xG6aTo/Wjs5YiWJk38g+slPfSWVRpAkOkm3R2zrwnngy/vbvYeKGwg4NO6SRbidtW mhdWE2gDzM7zLgYr+Xqa984EMiQCSpllN6XIjbxgCFaSPKr4t3hVUfkx3own4OSrA4 bGUbxyhac470nddV5v+viOcuErYDm6+T8rDxqqs0= Authentication-Results: smtpcorp1p.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Subject: [PATCH 4/4] kernel/fork: add option to use virtually mapped stacks as fallback From: Konstantin Khlebnikov To: Dave Hansen , linux-kernel@vger.kernel.org, Christoph Hellwig , linux-mm@kvack.org, Andy Lutomirski , Andrew Morton Date: Tue, 23 Jan 2018 13:55:32 +0300 Message-ID: <151670493255.658225.2881484505285363395.stgit@buzz> In-Reply-To: <151670492223.658225.4605377710524021456.stgit@buzz> References: <151670492223.658225.4605377710524021456.stgit@buzz> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Virtually mapped stack have two bonuses: it eats order-0 pages and adds guard page at the end. But it slightly slower if system have plenty free high-order pages. This patch adds option to use virtually bapped stack as fallback for atomic allocation of traditional high-order page. Signed-off-by: Konstantin Khlebnikov --- arch/Kconfig | 14 ++++++++++++++ kernel/fork.c | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index 400b9e1b2f27..c181ab263e7f 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -904,6 +904,20 @@ config VMAP_STACK the stack to map directly to the KASAN shadow map using a formula that is incorrect if the stack is in vmalloc space. +config VMAP_STACK_AS_FALLBACK + default n + bool "Use a virtually-mapped stack as fallback for directly-mapped" + depends on VMAP_STACK + help + With this option kernel first tries to allocate directly-mapped stack + without calling direct memory reclaim and fallback to vmap stack. + + Allocation of directly mapped stack faster than vmap if system a lot + of free memory and much slower if all memory is used or fragmented. + + This option neutralize stack overflow protection but allows to + achieve best performance for syscalls fork() and clone(). + config ARCH_OPTIONAL_KERNEL_RWX def_bool n diff --git a/kernel/fork.c b/kernel/fork.c index 457c9151f3c8..cc61a083954d 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -207,6 +207,17 @@ static unsigned long *alloc_thread_stack_node(struct task_struct *tsk, int node) struct vm_struct *stack; int i; +#ifdef CONFIG_VMAP_STACK_AS_FALLBACK + struct page *page; + + page = alloc_pages_node(node, THREADINFO_GFP & ~__GFP_DIRECT_RECLAIM, + THREAD_SIZE_ORDER); + if (page) { + tsk->stack_vm_area = NULL; + return page_address(page); + } +#endif + for (i = 0; i < NR_CACHED_STACKS; i++) { stack = this_cpu_xchg(cached_stacks[i], NULL); if (!stack)