Skip to contentSkip to conversation

no way to swapoff a deleted swap file?

DISCUSSION Peter Cordes 4 participants 4 messages Oct 15, 2008 – Oct 17, 2008 Memory management

lore
Share & tools
lore
#0 lore raw

I unlinked a swapfile without realizing I was still swapping on it.
Now my /proc/swaps looks like this:

Filename                                Type            Size    Used	Priority
/var/tmp/EXP/cache/swap/1\040(deleted)  file            1288644 1448	-1
/var/tmp/EXP/cache/swap/2\040(deleted)  file            1433368 0	-2

AFAICT, there's nothing I can pass to swapoff(2) that will make the
kernel let go of them. If that's the case, please consider this a feature request for a way to do this. Now I'm going to have to reboot before I can mkfs that partition.

If kswapd0 had a fd open on the swap files, swapoff /proc/$PID/fd/3
could possibly work. But it looks like the files are open but with no user-space accessable file descriptors to them. Which makes sense, except for this case.

thanks, and happy hacking,

Signature · 6 lines
#define X(x,y) x##y
Peter Cordes ;  e-mail: X(peter@cor , des.ca)

"The gods confound the man who first found out how to distinguish the hours!
 Confound him, too, who in this place set up a sundial, to cut and hack
 my day so wretchedly into small pieces!" -- Plautus, 200 BC
#1 lore raw
Quoted 11 lines · Peter Cordes

I unlinked a swapfile without realizing I was still swapping on it. Now my /proc/swaps looks like this:

Filename                                Type            Size    Used	Priority
/var/tmp/EXP/cache/swap/1\040(deleted)  file            1288644 1448	-1
/var/tmp/EXP/cache/swap/2\040(deleted)  file            1433368 0	-2

AFAICT, there's nothing I can pass to swapoff(2) that will make the
kernel let go of them. If that's the case, please consider this a feature request for a way to do this. Now I'm going to have to reboot before I can mkfs that partition.

Quoted 4 lines

If kswapd0 had a fd open on the swap files, swapoff /proc/$PID/fd/3
could possibly work. But it looks like the files are open but with no user-space accessable file descriptors to them. Which makes sense, except for this case.

Right, except that kswapd is per node, so we'd either have to add it to all kswapd instances or a random one. Also, kthreads don't seem to have a files table afaict.

But yes, I see your problem and it makes sense to look for a nice solution.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 17 lines · Peter Zijlstra
Quoted 11 lines · Peter Cordes

I unlinked a swapfile without realizing I was still swapping on it. Now my /proc/swaps looks like this:

Filename                                Type            Size    Used	Priority
/var/tmp/EXP/cache/swap/1\040(deleted)  file            1288644 1448	-1
/var/tmp/EXP/cache/swap/2\040(deleted)  file            1433368 0	-2

AFAICT, there's nothing I can pass to swapoff(2) that will make the
kernel let go of them. If that's the case, please consider this a feature request for a way to do this. Now I'm going to have to reboot before I can mkfs that partition.

Quoted 4 lines

If kswapd0 had a fd open on the swap files, swapoff /proc/$PID/fd/3
could possibly work. But it looks like the files are open but with no user-space accessable file descriptors to them. Which makes sense, except for this case.

Quoted 6 lines

Right, except that kswapd is per node, so we'd either have to add it to all kswapd instances or a random one. Also, kthreads don't seem to have a files table afaict.

But yes, I see your problem and it makes sense to look for a nice solution.

No immediate answer springs to my mind.

It's not something I'd want to add a new system call for. I guess we could put a magic file for each swap area somewhere down in /sys, and allow swapoff to act upon that.

If there were other good reasons to add such files, that could make sense. But although I'll willingly admit it's a lacuna, I don't think it's one worth bloating the kernel for.

(I would suggest that Peter keep a second link to his swapfiles somewhere safer; but that's then open to the converse complaint, that when he unlinks intentionally but forgets the safe link, the disk space remains mysteriously in use.)

Sorry for being unhelpful!
Hugh

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw
Quoted 11 lines · Hugh Dickins
Quoted 6 lines · Peter Zijlstra
Quoted 2 lines · Peter Cordes

I unlinked a swapfile without realizing I was still swapping on it.

I see your problem and it makes sense to look for a nice solution.

although I'll willingly admit it's a
lacuna, I don't think it's one worth bloating the kernel for.

Me too. The kernel shouldn't protect the administrator against all possible mistakes; and this mistake is one of them. Besides, who's to say it's always a mistake? Somebody might want their swap file to have zero links.

Do nothing.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>