How big should my swap partition be?

Ah-hah! Please excuse my Linux n00bness; I had no idea that a dd dump could be mounted like any other device!

To backup I ran dd if=/dev/sda1 of=/home/username/backup.img on a Linux VM. I'm an old-school Windows power user from the time I was in primary school, which was roughly 25 years ago, but need to use Linux a lot for work (I'm a web developer). I've gotten used to all the basic commands and some advanced web admin commands, but never knew dd was so freaking awesome LOL!

Anyway, after scp-ing the file off the VM and on to the router, then running mount /mnt/ntfs1/backup.img /mnt/backup, I get mount: can't setup loop device: No such file or directory. So how can I mount the image?

Thanks again mate; I really appreciate all your help and encouragement :smiley:

LOL sorry I guess I'm getting tired after having been at this all day.

There's nothing to explain about my extroot config really...just a run-of-the-mill extroot setup on a USB HDD, which I'm also using for two NTFS data partitions and now a swap partition as well.

Granted it may not actually help me with loading a large hosts file, which you would have seen if you read right to the end of my OP here :stuck_out_tongue: , but I'm just trying whatever I can to make it work.

1 Like

OH!!!!!!!!!!

Loading something large in dnsmasq would be something to try swap for...if you were having issues ("if it ain't broke, don't fix it" - as they say).

:+1:

1 Like

LOL totally :wink: Glad we're on the same page now! :smiley:

Except that it needs to be loaded to RAM for each DNS query as dnsmasq needs to evaluate the whole blocklist to see if a domain is on the list.

In theory swap may enable using a large blocklist, but I doubt that performance will improve. Possibly the DNS queries will slow down quite much. I still highly doubt that swap will help in dnsmasq performance (like I said the in abandoned "overcrowded" thread, which is shorter than this one...)

2 Likes

I agree my Adblock loads about 245,000 domains - my router has 512 MB of RAM...that's still not enough during heavy traffic (especially since my ISP upgraded me to 100 Mbps from 50 during the pandemic); and I can't imagine a performance improvement in the swap since the balance is actually traffic thru iptables/kernel/etc.

But, since I never intended to criticize...in fact I'm curious of the results - I await to see if the OP has success.

LOL sorry I never expected to get so many great answers here, nor to start diverging off the original question on slightly-unrelated tangents. Should we continue this discussion in that original thread?

No need. Just friendly advice that as most router functions are "real-time" oriented by nature, using flash or HDD as swap will slow you down quite much compared to pure RAM.

If you get good results from swap, then good for you :wink:

1 Like

LOL thanks mate, I'll definitely LYK how I go in the coming weeks. I'm going to enable SQM when I get around to it as well - reading the official guide now, but should probably get some sleep soon since it's 1 AM here :open_mouth:

I almost never work with entire disk images, most of the disks I have are REALLY big, so there's nowhere to put them and no purpose to them. :wink: so I'm rusty on how to loopback mount a file...

I think the method is something like:

losetup /backup.img
mount /dev/loop0 /mnt/backup
...do copy here...
losetup -d /dev/loop0

Thanks again Dan (hope you don't mind me calling you that LOL :stuck_out_tongue:), I'll give that a whirl and will annoy some other poor Linux pro via Google if need be. Happy Easter mate! :smiley:

OK so it's been almost a full day since I got this all completely set up, and so far I've noticed the following:

  1. Internet performance hasn't really changed, at least not as far as I can tell.
  2. The read/write performance of my NTFS data partitions is absolutely woeful! Windows (via Samba) struggles to read from the disk any faster than 2 or 3 MB/s, and writes are even worse!
  3. I'm not sure whether having a swap partition is the cause of 2. but it seems logical since it's the only thing that has changed besides the bad NTFS performance. The swap doesn't even seem to be being used though (it's currently showing 0% usage in LuCI -> Status -> Overview)!

I've been reading this SuperUser thread that seems to be related to 2., and from the comments there it seems as though the best course of action would be to scrap the NTFS-3G driver in favour of a newer, better-maintained alternative. But I haven't been able to find one yet :frowning_face:.

So if anyone can shed some light on this situation I would be forever grateful. MTIA! :slightly_smiling_face:

As predicted.

There are two issues I see here, both NTFS (not a native filesystem or Linux) and samba are somewhat resource hungry (and samba requires special care to configure/optimize). On an OpenWrt router, I would always try to use a more linuxy filesystem. Samba is often the best choice for fille-serving to windows machines, but IHMO for decent performance need something beefier than a trusty old MIPS based archer C7.

I would be amazed if swap would be the cause, but testing it is easy, just issue swapoff -a and swap will be disabled... use free on the command line to get an idea about swap usage, and do not connect via LUCI while you benchmark, the GUI can be quite resource hungry, at least on an archer C7 class of router...

Or better yet, scrap NTFS no matter the flavor for ext4, btfs, xfs, or god-forbid zfs...

1 Like

Please don't take offence to this as I really appreciate you trying to help, but do you really expect me to backup a 1TB hard drive spread across two partitions to...God only knows where!...and then format to a Linux filesystem and copy the data back??

I don't see why I should have to since things were fine a couple of days ago, and I can't even imagine how long that would take or how dangerous, or expensive, it would be...

Once again, I hope those comments don't offend you since you had no way of knowing how much data is involved, or how precious that data is to me (very, my career and therefore livelihood would end without it!).

One more thing: you seem to be a proponent of Linux in general, which is perfectly fine, but I am a proponent of Windows, at least for myself. If I could do everything I need to for bread and butter on Windows, I 150% would :stuck_out_tongue: Given that, the only reason I'm using OpenWrt at all is because there's no Microsoft equivalent.

And let's face it: if there was, I'd be moaning about even-worse network performance LOL (I will definitely concede that a Linux-based server or even PC seems to run a lot faster and smoother than any MS product ever LOL. I only stick with them because I'm so used to the way everything works in their world).

Sorry guys I went off on a bit of a tangent there! But to address moeller0's comment

I just wanted to add something that amazed me as well: disabling swap did increase disk performance! Not to the level that I would get from a PC, but by ~100%! My read speeds are roughly doubled when disabling swap, so I guess the disk doesn't like being (not) used for swap, extroot and NTFS data all at once!

Mind you I didn't take his/her suggestion to close LuCI when benchmarking, so that's next :wink:

Question, the swap device is not on the same disk as your data, I assume? +1 for testing :wink:

1 Like

LOL I thought I had been pretty clear about that from the get go. Obviously not!

I am a cheapskate and so yes, I only have a single 1 TB USB HDD on which I'm trying to run everything. I have it partitioned like so:

root@OpenWrt:~# fdisk -l /dev/sda
Disk /dev/sda: 931.53 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: External USB 3.0
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x98dd558e

Device     Boot     Start        End    Sectors   Size Id Type
/dev/sda1            2048    1050623    1048576   512M 82 Linux swap / Solaris
/dev/sda2         1050624    2099199    1048576   512M 83 Linux
/dev/sda3         2099200  272631807  270532608   129G  7 HPFS/NTFS/exFAT
/dev/sda4       272631815 1953523711 1680891897 801.5G  7 HPFS/NTFS/exFAT

I really do not expect anything, I try to give my opinion, but hope/assume you make your own policy decisions as you know much more about your constraints and desires.
So no offense taken :wink:

That does not fit my self image, I try to select/recommend decent tools for the issue/challenge at hand. For attaching a backing disk to a Linux-based router, I still stand by my preference to use a native Linux filesystem (but I understand that this might not be ideal for a number of other reasons, like if a disk needs to be shared between windows and linux).

Well, you can just use sharing from windows to distribute file data in your network, no? While I understand the lure to make a router that runs 24/7 anyway also take over additional server duty (that is convenient to have active 24/7), I also think it is quite some security risk to attached precious data like in your case to a device that needs to be network attached and directly reachable from the outside.

I am sure that windows server variants are more than qualified for your file-serving needs ;).

But probably in a different forum, so that would be somebody else's problem :wink:

I might have agreed with you 1 or 2 decades ago, but the windows NT based product line has been rather reliable, and windows10 is rather enjoyable IMHO (if only since its WSL/WSL2 gives decent access to linux/unix based applications in addition to native windows programs).

4 Likes

Well, if swap is used it will eat into the file system operations per second budget your device/usb-bus? can deliver... especially over a conceptually slow bus like USB2 this can get painful even if swap throughput might be rather low.

2 Likes

Yeah I think I might have to buy a cheap USB hub and flash drive and set up the flash drive as swap/extroot. Would that hurt things even more though?

The HDD is USB 3 but unfortunately the router only provides a USB 2 port :frowning: And upgrading it is not an option since I only just bought the C7 a few months ago!