From a472eaceafe44a6d0be7687c70fb108eee16197b Mon Sep 17 00:00:00 2001 From: Jong Eun Lee Date: Fri, 14 Nov 2025 18:28:45 +0800 Subject: [PATCH 1/2] feat(FR-1681): implement automatic shared memory calculation in session creation --- react/src/hooks/useStartSession.tsx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/react/src/hooks/useStartSession.tsx b/react/src/hooks/useStartSession.tsx index f8dcf4277c..2c0e859ac9 100644 --- a/react/src/hooks/useStartSession.tsx +++ b/react/src/hooks/useStartSession.tsx @@ -10,7 +10,11 @@ import { useTranslation } from 'react-i18next'; import { fetchQuery, graphql, useRelayEnvironment } from 'react-relay'; import { useStartSessionCreationQuery } from 'src/__generated__/useStartSessionCreationQuery.graphql'; import { transformPortValuesToNumbers } from 'src/components/PortSelectFormItem'; -import { RESOURCE_ALLOCATION_INITIAL_FORM_VALUES } from 'src/components/SessionFormItems/ResourceAllocationFormItems'; +import { + RESOURCE_ALLOCATION_INITIAL_FORM_VALUES, + AUTOMATIC_DEFAULT_SHMEM, +} from 'src/components/SessionFormItems/ResourceAllocationFormItems'; +import { compareNumberWithUnits } from 'src/helper'; import { SessionLauncherFormValue, SessionResources, @@ -144,6 +148,20 @@ export const useStartSession = () => { minimumValues: StartSessionWithDefaultValue, ) => { const mergedValue = _.merge({}, defaultFormValues, minimumValues); + + // Apply automatic shmem calculation if enabledAutomaticShmem is true + if (mergedValue.enabledAutomaticShmem && mergedValue.resource?.mem) { + const mem = mergedValue.resource.mem; + + // Apply the same logic as ResourceAllocationFormItems + // If mem > 4G, set shmem to 1G, otherwise use AUTOMATIC_DEFAULT_SHMEM (64m) + if (compareNumberWithUnits(mem, '4g') >= 0) { + mergedValue.resource.shmem = '1g'; + } else { + mergedValue.resource.shmem = AUTOMATIC_DEFAULT_SHMEM; + } + } + return startSession(mergedValue as SessionLauncherFormValue); }; const startSession = async (values: SessionLauncherFormValue) => { From a627ebb291aa331df089ecf5c43b75f40e7fe67f Mon Sep 17 00:00:00 2001 From: Jong Eun Lee Date: Wed, 19 Nov 2025 09:45:01 +0800 Subject: [PATCH 2/2] Apply suggestions from code review --- react/src/hooks/useStartSession.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react/src/hooks/useStartSession.tsx b/react/src/hooks/useStartSession.tsx index 2c0e859ac9..78c49e230d 100644 --- a/react/src/hooks/useStartSession.tsx +++ b/react/src/hooks/useStartSession.tsx @@ -154,7 +154,7 @@ export const useStartSession = () => { const mem = mergedValue.resource.mem; // Apply the same logic as ResourceAllocationFormItems - // If mem > 4G, set shmem to 1G, otherwise use AUTOMATIC_DEFAULT_SHMEM (64m) + // If mem >= 4G, set shmem to 1G, otherwise use AUTOMATIC_DEFAULT_SHMEM (64m) if (compareNumberWithUnits(mem, '4g') >= 0) { mergedValue.resource.shmem = '1g'; } else {